WorksheetsPython Control Structures Quiz Review - CodeHS Unit 4 Review
Total questions: 17
Worksheet time: 51mins
Which of the following Boolean expressions is equivalent to the expression?
a AND (b OR c)
(a AND b) OR (a AND c)
(b AND c) OR a
(a AND b) AND (a AND c)
(a AND b) OR c
What is the value of the boolean variable can_graduate at the end of this program?
earned_credits = 120
no_fees_owed = True
can_graduate = earned_credits >= 115 and no_fees_owed = True
True
False
None, there is a syntax error.
Yes, can graduate.
What is the last thing printed by the following program?
start = 24
stop = 9
for i in range (start, stop -1, -3):
if i % 3 == 0:
print(i *2)
else:
print(i)
9
18
0
3
How many times will the following program print "Call me asparagus."?
i = 0
while i < 10:
print("Call me asparagus.")
This program will loop infinitely.
5
10
0
What will be the output of this program?
number = 9
greater_than_zero = number > 0
if greater_than_zero:
if number > 5:
print(number)
0
9
False
Nothing will print
The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤.
As well, AND, OR and NOT are used instead of and, or and not.
A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.
Determine what the following expression would evaluate to.
(12 != 8 AND 19 < 6) OR 68 < 5
yes
true
false
no
What is printed by the following program?
is_snowing = True
is_windy = True
is_blizzard = is_snowing AND is_windy
is_winter = False
is_cold = is_snowing or is_winter
print("Is it cold: " + str(is_cold))
Is it cold: True
Is it cold: False
Is it cold: yes
Is it cold: no
We want to print the phrase "Another day, another victory for the OG" exactly 19 times. What kind of control structure should we use?
If Statement
While Loop
Break Statement
For Loop
The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem.
Change the True in line 3 to be password != SECRET_PASSWORD so that the program doesn't loop infinitely.
Change the True in line 3 to be password == SECRET_PASSWORD so that program doesn't loop infinitely.
Add a break; statement after line 6 so that the program doesn't loop infinitely.
Put line 7 inside of an else statement.
We want to simulate constantly rolling a dice until we get an even number. What kind of loop should we use?
For loop
While Loop
Hula Hoop
Infinite Loop
What is the output of the following program?
result = 1
max = 3
for i in range(1, max+1)
result *= i
print(result)
1
3
6
0
number_one = 10
number_two = 20
if number_one == 10:
print(1)
if number_one > 10:
print(2)
if number_two < 10:
print(3)
if number_one < number_two:
print(4)
if number_one != number_two:
print(5)
1
1
3
5
1
4
5
1
2
5
Which of the following returns a random number between 1 and 75?
randint(1,76)
randint(1,75)
random.randint(1,75)
random.randint(1,76)
What will be the output when the following code runs?
doing_work = False
print("Student doing work?: " + str(not doing_work)
Student doing work?: True
Student doing work?: False
True
False
ambOneAvail AND (inZone OR NOT ambTwoAvail)
ambOneAvail AND (inZone OR ambTwoAvail)
ambOneAvail OR (inZone OR ambTwoAvail)
NOT ambTwoAvail AND (inZone OR ambOneAvail)
What will be the output of the following program?
number = 7
greater_than_zero = number > 0
if greater_than_zero:
if number > 5:
print(number)
0
7
False
Nothing will print
What is the output of the following program?
result = 1
max = 4
for i in range(1, max+1)
result *= i
print(result)
1
4
24
0
