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)) ?

A

5.9

25
Q

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

A. end

26
Q

Which is not a Python keyword for decision structures:

A. if
B. else
C. elif
D. elselif

A

D.

27
Q

Which keyword or symbol can be used to form a compound logical expression:
A. &
B. &&
C. and

A

C. and

28
Q

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

A

C.

29
Q

True or False: An if statement can be nested under another if statement.

A

True

30
Q

True or False: In combination with an if statement, there can be at most one elif statement.

A

False

31
Q

What are the values that range(3) will generate?

A

0,1,2

32
Q

True or False: With repetition, program float may move to a prior statement.

A

True

33
Q

True or False: Repetition can be used to process different scenarios.

A

True

34
Q

Which is not a logical operator that can be used in a while statement?
A. <=
B.=<
C.==

A

B.

35
Q

A program that incorrectly keeps repeating is referred to as having a(n):

A

Infinite loop

36
Q

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)

A

0.3

37
Q

True or False: The return statement displays the result to the screen.

A

False

38
Q

True or False: Python allows you to define your own functions.

A

True

39
Q

The statements indented after the function’s signature is called the:
A. body
B.core
c. functional
d.None of the above

A

A.body

40
Q

The keyword to begin the definition of a function is:

A

def

41
Q

True or False:A function cannot call another function.

A

False

42
Q

If squares = [1, 4, 9, 16, 25], what is the value of squares[1:3] ?

A

4,9

43
Q

True or False:A tuple’s items can be access by square brackets, similar to lists.

A

True

44
Q

What is the output of the following program:

alist = [ ]

for i in range(3):

alist.append(i**2)

print(alist)

A

0,1,4

45
Q

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

A. alist.clear()

46
Q

What is the output of the following:

alist = [1, 4, 9]

sum = 0

for value in alist:

sum += value

print(sum)

A

14

47
Q

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

A. for adict:

48
Q

What keyword can be used to remove a key and its value from a dictionary?
A.del
B.remove
C.delete
D.update

A

A.del

49
Q

How can an empty set be created?
A.set()
B.{}
C.emptySet()

A

A. set()

50
Q

True or False: In contrast with lists, a dictionary cannot be created as empty.

A

False

51
Q

True or False: As compared with a dictionary, a list is designed to be faster for lookup by a key.

A

False

52
Q

True or False: Slicing alters the original string, as opposed to creating a new string.

A

False

53
Q

Which string method returns either True or False ?
A.startswith()
B.find()
C.rfind()
D.count()

A

A.startswith()

54
Q

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

A

B.

55
Q

If s=’Hello’, what is returned by s.count(‘l’) ?

A

2

56
Q

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.

A

B.

57
Q
A
58
Q
A