Advanced operations-conditional statements & loops Flashcards

1
Q

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

A

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

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

What is the number of iterations the following while loop will perform before terminating?

x = 4
while x < 10:
print(x+1)

A

Infinite

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

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?

A

Depends on when the user types “quit”

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

If break is invoked

A

the else block associated with the while loop is not executed

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

hat is the effect of the pass statement within a nested while loop being invoked?

A

There is no effect on code execution

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

What is the output of this while loop?

x = 8
while x < 10: print(x) x += 1

A

Syntax error

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