quiz 2 Flashcards

1
Q

What is the output of the print() statement after the following code:

m = 2
for n in range(3, 15, 5):
n += m + 2
print(n)

A

17

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

After running the following Python code, what will the variable x_list contain?

x_list = []
for n in range(4):
x_list.append(n**2)

A

[0, 1, 4, 9]

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

What is the output printed to the console after executing the following statements?

x = [“Fall”]
y = [“Spring”, “Summer”, “Winter”]
z = x + y
print(z)

A

[ ‘Fall’, ‘Spring’, ‘Summer’, ‘Winter’]

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

What is the output printed to the console after the following statements?

x = [[1], 2]
y = x.copy()
y[0][0] = 100
print(x, y)

A

[[100], 2] [[100], 2]

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

What is the result of running the following statements?

x = {“salmon”: “fish”, “orca”: “whale”}
y = x[“fish”]
print(y)

A

Code generates KeyError

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

What is the output of the following?

for x in range(10, 20, 2):
print(x, end=” “)

A

10 12 14 16 18

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

What is the output after the following statements?

x = 100
def new_function():
print(x)

new_function()

A

100

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

f we run the following Python code:

m = [(1,2), (3,4)]
for x, y in m:
print(x, y, end=” “)

What will be the output printed to the console?

A

1 2 3 4

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

What is output after the following statement?

x = 1
y = 2
z = x == y
print(z)

A

False

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

What is the data type of x?

x = (“Boston University”)

A

string

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