Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Control Structures Quiz Review - CodeHS Unit 4 Review

Total questions: 17

Worksheet time: 51mins

Name
Class
Date
1.

Which of the following Boolean expressions is equivalent to the expression?

a AND (b OR c)

a)

(a AND b) OR (a AND c)

b)

(b AND c) OR a

c)

(a AND b) AND (a AND c)

d)

(a AND b) OR c

2.

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

a)

True

b)

False

c)

None, there is a syntax error.

d)

Yes, can graduate.

3.

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)

a)

9

b)

18

c)

0

d)

3

4.

How many times will the following program print "Call me asparagus."?

i = 0

while i < 10:

print("Call me asparagus.")

a)

This program will loop infinitely.

b)

5

c)

10

d)

0

5.

What will be the output of this program?

number = 9

greater_than_zero = number > 0

if greater_than_zero:

if number > 5:

print(number)

a)

0

b)

9

c)

False

d)

Nothing will print

6.

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

a)

yes

b)

true

c)

false

d)

no

7.

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))

a)

Is it cold: True

b)

Is it cold: False

c)

Is it cold: yes

d)

Is it cold: no

8.

We want to print the phrase "Another day, another victory for the OG" exactly 19 times. What kind of control structure should we use?

a)

If Statement

b)

While Loop

c)

Break Statement

d)

For Loop

9.

The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem.

a)

Change the True in line 3 to be password != SECRET_PASSWORD so that the program doesn't loop infinitely.

b)

Change the True in line 3 to be password == SECRET_PASSWORD so that program doesn't loop infinitely.

c)

Add a break; statement after line 6 so that the program doesn't loop infinitely.

d)

Put line 7 inside of an else statement.

10.

We want to simulate constantly rolling a dice until we get an even number. What kind of loop should we use?

a)

For loop

b)

While Loop

c)

Hula Hoop

d)

Infinite Loop

11.

What is the output of the following program?

result = 1

max = 3

for i in range(1, max+1)

result *= i

print(result)

a)

1

b)

3

c)

6

d)

0

12.

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)

a)

1

b)

1

3

5

c)

1

4

5

d)

1

2

5

13.

Which of the following returns a random number between 1 and 75?

a)

randint(1,76)

b)

randint(1,75)

c)

random.randint(1,75)

d)

random.randint(1,76)

14.

What will be the output when the following code runs?

doing_work = False

print("Student doing work?: " + str(not doing_work)

a)

Student doing work?: True

b)

Student doing work?: False

c)

True

d)

False

15.
a)

ambOneAvail AND (inZone OR NOT ambTwoAvail)

b)

ambOneAvail AND (inZone OR ambTwoAvail)

c)

ambOneAvail OR (inZone OR ambTwoAvail)

d)

NOT ambTwoAvail AND (inZone OR ambOneAvail)

16.

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)

a)

0

b)

7

c)

False

d)

Nothing will print

17.

What is the output of the following program?

result = 1

max = 4

for i in range(1, max+1)

result *= i

print(result)

a)

1

b)

4

c)

24

d)

0