Python in Data Structures and Algorithms Flashcards

1
Q

What is the output for the following code?

print(len(“95637+12”))

a.) 15
b.) 95649
c.) 8
d.) 95659

A

c.) 8

Calculating the length of the string.

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

Read the code below, what will be printed in the output?

score = 67
if score < 80 and score > 70:
print(“A”)
elif score < 90 or score > 80:
print(“B”)
elif score > 60:
print(“C”)
else:
print(“D”)

A

Output = B

There is an or between <90 OR >80. Order of operations.

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

What will be printed in the console?

def a_function(a_parameter):
a_variable = 15
return a_parameter
a_function(10)
print(a_variable)

a.) NameError
b.) 5
c.) 10
d.) 15

A

a.) NameError

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

What will be printed as the output?

def outer_function(a, b):
def inner_function(c, d):
return c + d
return inner_function(a, b)

result = outer_function(5, 10)
print(result)

a.) SyntaxError
b.) 15
c.) 10
d.) (5, 10)

A

b.) 15

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

Which line of Python code is valid?

a.) var a = 12
b.) a = 12
c.) a: 12
d.: 12 = a

A

b.) a = 12

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

Which is the best variable name for Player 1’s username?

a.) p1 user name = “jackbauer”
b.) 1_player_username = “jackbauer”
c.) player1_username = “jackbauer”
d.) p1u = “jackbauer”

A

c.) player1_username = “jackbauer”

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

Which block of code will produce an error? For extra points, which type of error do you think it will produce?

a.) time_until_midnight = “5”
print(“There are “ + time_until_Midnight + “ hours until midnight”)

b.) num_hours = “5”
print(“There are “ + num_hours + “ hours until midnight”)

c.) time_until_midnight = “5”
print(“There are “+time_until_midnight +” hours until midnight”)

A

a.) time_until_midnight = “5”
print(“There are “ + time_until_Midnight + “ hours until midnight”)

NameError is produced because they do not match in print statement and variable.

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

How is Stack Data Structured implemented in Python?

A
  1. list
  2. collections.deque
  3. queue.LifoQueue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly