Conditional Statements & Loops: While Loops in Python
What is the output of the following code? my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] i = 0 while i < len(my_list): print(my_list[i]) i += 3
a d g
What is the output of the following code? my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] vowels = ['a', 'e', 'i', 'o', 'u'] i = 0 while i < len(my_list): if(my_list[i] in vowels): i += 1 continue print(my_list[i]) i += 2
b d f h
Which TWO of the following statements about while and for loops are TRUE?
for 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
What is the number of iterations the following while loop will perform before terminating? x = 4 while x < 4+6: print(x) x += 1
6
Consider the code below: 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"
Which of the following statements about the use of break statements in a while loop are true?
If break is invoked, the else block associated with the while loop is not executed
What is the number of iterations the following while loop will perform before terminating? x = 4 while x < 10: print(x+1)
Infinite
What is the output of this while loop? x = 8 while x < 10: print(x) x += 1
Syntax error
What is the effect of the pass statement within a nested while loop being invoked?
There is no effect on code execution