4.12.1 Python Control Structures Quiz
Question:
Answer: REPEAT 2 TIMES
{
MOVE_FORWARD ()
MOVE_FORWARD ()
ROTATE_LEFT ()
}
Question: We want to print the phrase “CodeHS is the best” exactly 25 times. What kind of control structure should we use?
Answer: For loop
Question:
Answer: a AND (b OR c)
Question: What will the following program print when run?
for j in range(2):
for i in range(6, 4, -1):
print (i)
Answer: 6
5
6
5
Question: What will the following program print when run?
numberone = 5 numbertwo = 10 if numberone == 5: print(1) if numberone > 5: print(2) if numbertwo < 5: print(3) if numberone < numbertwo: print(4) if numberone != number_two: print(5)
Answer: 1
4
5
Question: What is the value of the boolean variable can_vote at the end of this program?
age = 17
is_citizen = True
canvote = age >= 18 and iscitizen
Answer: False
Question: Which of the following could NOT be an output from the following code?
mystery_num = 10 * random.randint(1,10)
print(mystery_num)
Answer: 0
Question: 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)
Answer: 20
Question:
Answer: The program does not work as intended but rather it displays the number squared.
Question: What is the output of the following program?
result = 0 max = 5 for i in range(max): result += i print(result)
Answer: 10