Advanced operations-conditional statements & loops Flashcards
Which TWO of the following statements about while and for loops are TRUE?
while loops continue to loop while the condition is True and end when the condition evaluates to False
for loops continue with iterations until a condition evaluates to True/False
for loops iterate over a sequence without the user needing to maintain an index to that sequence
while loops iterate over a sequence without the user needing to maintain an index to that sequence
while loops continue to loop while the condition is True and end when the condition evaluates to False
for loops iterate over a sequence without the user needing to maintain an index to that sequence
What is the number of iterations the following while loop will perform before terminating?
x = 4
while x < 10:
print(x+1)
Infinite
inventory = []
item = “”
while item != “quit”:
item = input(“Enter an item to add to the inventory: “)
print(“Adding item:”, item)
inventory.append(item)
What is the number of iterations of the while loop?
Depends on when the user types “quit”
If break is invoked
the else block associated with the while loop is not executed
hat is the effect of the pass statement within a nested while loop being invoked?
There is no effect on code execution
What is the output of this while loop?
x = 8
while x < 10: print(x) x += 1
Syntax error