Python in Data Structures and Algorithms Flashcards
What is the output for the following code?
print(len(“95637+12”))
a.) 15
b.) 95649
c.) 8
d.) 95659
c.) 8
Calculating the length of the string.
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”)
Output = B
There is an or between <90 OR >80. Order of operations.
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.) NameError
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)
b.) 15
Which line of Python code is valid?
a.) var a = 12
b.) a = 12
c.) a: 12
d.: 12 = a
b.) a = 12
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”
c.) player1_username = “jackbauer”
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.) 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 is Stack Data Structured implemented in Python?
- list
- collections.deque
- queue.LifoQueue