MSBC 5070 (Midterm Review) Flashcards

1
Q

Fill in the blanks to complete the code that will ask a user for their name and store the result in a variable called, name.

xxxxx=xxxxxx(“What is your name?”)

A

name=input

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the expression, 9 % 3, evaluate to?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the correct Python function to convert a value to a string

A

str()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write the code to import the random module:

A

import random

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Is the following an assignment or expression: eggs=2

A

assignment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Is the following an assignment or expression: 2

A

expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does Python return when the following function is executed?

str(245)

A

‘245’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

False and True evaluates to:

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False evaluates to:

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write code that uses a string method to return a Boolean value indicating whether or not a variable, name, is in Title Case format.

A

name.istitle()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does Python return when the following function is executed?

int(‘245’)

A

245

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

After the following two lines of python code runs, what is the value of the revenue variable?

revenue = 1000

revenue + 10

A

1000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Given the following variable:

studentGrades = [10, 10, 10, 85, 85, 90, 100, 100,100]

Write the sub list that would be returned by the following code:

studentGrades[2:5]

A

10,85,85

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the % operator in Python?

A

Modulus

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the correct Python function to convert a value to a floating-point number.

A

float()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

By default, the while loop is an:

A.Entry controlled loop
B.Exit controlled loop

A

A.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Fill in the blanks to complete the python code that will find the remainder when 23 is divided by 3:

A

23%3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Fill in the blanks to complete the code that uses a string method to convert a variable, name, to upper case.

A

name.upper()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Consider the following code segment:

theSum = 0.0
while True:

 number = input("Enter a number: ")
 if number == "":
	        break
	 theSum += float(number)

How many times will the loop run?

A. None
B. At least Once
C. Infinite while loop
D. None of the above

A

B.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

True and True and True and False evaluates to:

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Given the following list variable:

studentGrades = [10, 10, 10, 85, 85, 90, 100, 100,100]

What would be returned by the following code:

studentGrades[5]

A

90

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

In order to prompt for and get a user’s input via the keyboard, which Python function can be used?

A

input()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What can be provided as an argument within the parentheses of the input() function?

A. a string
B. an integar
C. a float
D. a comment

A

A.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Assume variables have these values:

a = -5.94

b = 1

What is the value of abs(round(a, b)) ?

25
When using the print() function, what named parameter can be used to control what is done after all items are displayed? A. end B. delim C. sep D. space
A. end
26
Which is not a Python keyword for decision structures: A. if B. else C. elif D. elselif
D.
27
Which keyword or symbol can be used to form a compound logical expression: A. & B. && C. and
C. and
28
Assuming reply is a string variable, which is a valid statement? A.ok = True (reply == 'y') False B.ok = True (reply = 'y') False C.ok = True if (reply == 'y') else False D.ok = if reply == 'y' then True else False
C.
29
True or False: An if statement can be nested under another if statement.
True
30
True or False: In combination with an if statement, there can be at most one elif statement.
False
31
What are the values that range(3) will generate?
0,1,2
32
True or False: With repetition, program float may move to a prior statement.
True
33
True or False: Repetition can be used to process different scenarios.
True
34
Which is not a logical operator that can be used in a while statement? A. <= B.=< C.==
B.
35
A program that incorrectly keeps repeating is referred to as having a(n):
Infinite loop
36
What will be displayed when the following program is run? def div(num, denom, decimals=2): print(round(num/denom, decimals)) div(1,3, decimals=1)
0.3
37
True or False: The return statement displays the result to the screen.
False
38
True or False: Python allows you to define your own functions.
True
39
The statements indented after the function's signature is called the: A. body B.core c. functional d.None of the above
A.body
40
The keyword to begin the definition of a function is:
def
41
True or False:A function cannot call another function.
False
42
If squares = [1, 4, 9, 16, 25], what is the value of squares[1:3] ?
4,9
43
True or False:A tuple's items can be access by square brackets, similar to lists.
True
44
What is the output of the following program: alist = [ ] for i in range(3): alist.append(i**2) print(alist)
0,1,4
45
What statement can be used to remove all items from a list named alist? A.alist.clear() B.clear(alist) C.del alist D.delete alist
A. alist.clear()
46
What is the output of the following: alist = [1, 4, 9] sum = 0 for value in alist: sum += value print(sum)
14
47
Assuming adict is a dictionary, which is not a valid statement: A.for adict: B.for k in addict.keys() C.for v in addict.keys() D.for k,v in addict.items() E. None of the above F.All the above
A. for adict:
48
What keyword can be used to remove a key and its value from a dictionary? A.del B.remove C.delete D.update
A.del
49
How can an empty set be created? A.set() B.{} C.emptySet()
A. set()
50
True or False: In contrast with lists, a dictionary cannot be created as empty.
False
51
True or False: As compared with a dictionary, a list is designed to be faster for lookup by a key.
False
52
True or False: Slicing alters the original string, as opposed to creating a new string.
False
53
Which string method returns either True or False ? A.startswith() B.find() C.rfind() D.count()
A.startswith()
54
In a string slice, what is assumed if the position after the colon is omitted, for example like s[1:] ? A.The slice ends at position 1 B.The slice ends at the last position of the original string C.The slice is the same as the original string D.an error will be generated
B.
55
If s='Hello', what is returned by s.count('l') ?
2
56
What is the difference between the string methods strip() and rstrip()? A.These are different names but behave the same B.strip() returns a result that removes leading and trailing whitespace; rstrip() returns a result that removes trailing whitespace. C.strip() removes whitespace, rstrip() removes the \r character.
B.
57
58