Python Control Structures Quiz
1. What is the last thing printed by the following program?
start = 30 stop = 10 for I in range(start, stop - 1, -5): if I % 2 == 0: print(I *
2) else: print(I): 20
2. We want to simulate constantly flipping a coin until we get 3 heads in a
row. What kind of loop should we use?: While Loop
3. How many times will the following program print "hello"?: This code will loop
infinitely
4. The following code continually asks the user for a password until they
guess the correct password, then ends. But there is one problem.: Add a break; statement
after line 6 so that the program doesn't loop infinitely
5. What will the following program print when
run? for j in range(2): for I in range(6, 4, -1):
print (): 6
5
6
1/
6
, 5
6. What is the value of the Boolean variable can_ vote at the end of this
program?
age = 17 is _citizen = True can _vote = age >= 18 and is citizen: False
7. What will be the output of this program?
number = 5 greater_ than _zero = number > 0 if greater_ than _zero:
print(number): 5
8. What will be the output of this program?
number = 5 greater than zero = number > 0 if greater than zero: if number >
5: print(number): Nothing will print
9. What is printed by the following program?
Is raining = False is _cloudy = False is_ sunny = not is _raining and not is_ cloudy
is _summer = False is_ warm = is _sunny or is _summer print("Is it warm: " +
2/
6
1. What is the last thing printed by the following program?
start = 30 stop = 10 for I in range(start, stop - 1, -5): if I % 2 == 0: print(I *
2) else: print(I): 20
2. We want to simulate constantly flipping a coin until we get 3 heads in a
row. What kind of loop should we use?: While Loop
3. How many times will the following program print "hello"?: This code will loop
infinitely
4. The following code continually asks the user for a password until they
guess the correct password, then ends. But there is one problem.: Add a break; statement
after line 6 so that the program doesn't loop infinitely
5. What will the following program print when
run? for j in range(2): for I in range(6, 4, -1):
print (): 6
5
6
1/
6
, 5
6. What is the value of the Boolean variable can_ vote at the end of this
program?
age = 17 is _citizen = True can _vote = age >= 18 and is citizen: False
7. What will be the output of this program?
number = 5 greater_ than _zero = number > 0 if greater_ than _zero:
print(number): 5
8. What will be the output of this program?
number = 5 greater than zero = number > 0 if greater than zero: if number >
5: print(number): Nothing will print
9. What is printed by the following program?
Is raining = False is _cloudy = False is_ sunny = not is _raining and not is_ cloudy
is _summer = False is_ warm = is _sunny or is _summer print("Is it warm: " +
2/
6