wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CodeHS - Intro to Python - Conditionals Quiz

Total questions: 15

Worksheet time: 30mins

Name
Class
Date
1.

What will print to the screen when the following program is run?


number = 5

greater_than_zero = number > 0

print(type(number))

a)

5

b)

True

c)

<type ‘int’>

d)

<type ‘bool’>

2.

What will print to the screen when the following program is run?


number = 5

less_than_zero = number < 0

print(type(less_than_zero))

a)

5

b)

False

c)

<type ‘int’>

d)

<type ‘bool’>

3.

What will be the output of this program?


number = 5

greater_than_zero = number > 0


if greater_than_zero:

print(number)

a)

0

b)

5

c)

True

d)

Nothing will print

4.

What will be the output of this program?


number = 5

greater_than_zero = number > 0


if greater_than_zero:

if number > 5:

print(number)

a)

0

b)

5

c)

True

d)

Nothing will print

5.

What will be the output of this program?


number = 5

less_than_zero = number < 0


if less_than_zero:

print(number)


number = number - 10

less_than_zero = number < 0


if less_than_zero:

print(number)

a)

5

5

b)

-5

c)

5

-5

d)

Nothing will print

6.

What will be the output of this program?


number = 5

greater_than_zero = number > 0

less_than_zero = number < 0


if greater_than_zero:

print(number)

if less_than_zero:

print(number + 1)

if greater_than_zero and less_than_zero:

print(number + 2)

if greater_than_zero or less_than_zero:

print(number + 3)

a)

5

b)

5

7

c)

5

7

8

d)

5

8

7.

What will the following program print when run?


above_16 = True

has_permit = True

passed_test = False


if above_16 and has_permit and passed_test:

print("Issue Driver's License")

elif above_16 or has_permit or passed_test:

print("Almost eligible for Driver's License")

else:

print("No requirements met.")

a)

Issue Driver’s License

b)

Almost eligible for Driver’s License

c)

No requirements met

d)

Nothing will print

8.

What will the following program print when run?


number_one = 5

number_two = 10


if number_one == 5:

print(1)

if number_one > 5:

print(2)

if number_two < 5:

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

d)

1

4

5

9.

What will the following program print when run?


number_one = 5

number_two = 10


if number_one == 5:

print(1)

elif number_one > 5:

print(2)

elif number_two < 5:

print(3)

elif number_one < number_two:

print(4)

elif number_one != number_two:

print(5)

else:

print(6)

a)

1

b)

1

3

5

c)

1

4

d)

1

4

5

10.

What does this program print?


height = 65

gender = "female"


if height < 62:

print "You are below average height"

elif height > 69:

print "You are above average height"

else:

print "You are average height"

a)

You are below average height

b)

You are above average height

c)

You are average height

d)

You are below average height

You are above average height

11.

What does this program print?


height = 65

gender = "female"


if height < 62 or (height < 69 and gender == "male"):

print "You are below average height"

elif height > 69 or (height > 62 and gender == "female"):

print "You are above average height"

else:

print "You are average height"

a)

You are below average height

b)

You are above average height

c)

You are average height

d)

You are below average height

You are above average height

12.

What does this program print?


favorite_color = "blue"


if favorite_color != "green":

print "But green is the color of grass!"

if favorite_color == "red":

print "I like red, too!"

if favorite_color == "blue":

print "Blue is the best"

if favorite_color != "yellow":

print "But yellow is the color of school buses!"

a)

But green is the color of grass!

Blue is the best

But yellow is the color of school buses!

b)

But green is the color of grass!

c)

But green is the color of grass!

I like red, too!

Blue is the best

But yellow is the color of school buses!

d)

Blue is the best

13.

What does this program print?


favorite_color = "blue"


if favorite_color != "blue":

if favorite_color != "red":

print "Must be yellow"

elif favorite_color == "blue":

if favorite_color != "yellow":

print "Must be blue"

elif favorite_color == "blue":

if favorite_color != "yellow":

print "I like purple"

else:

if favorite_color == "blue":

print "Blue is the best"

a)

Must be yellow

b)

Must be blue

I like purple

Blue is the best

c)

Must be blue

d)

Blue is the best

14.

How would you round the number held in the variable pi to 3.14?


pi = 3.14159265

a)

round(pi)

b)

round(pi, 3)

c)

round(3, pi)

d)

round(pi, 2)

15.

Why should you use round when you compare two numbers that have type float?

a)

If you don’t, Python will only compare the whole part and discard the decimal part.

b)

You don’t have to, but it’s good style. All of the comparisons will still work out the same way.

c)

Sometimes numbers can be rounded in unexpected ways based on how Python computes them. Therefore, it is best to use round in order to make sure both numbers are rounded the same way.

d)

You should always use round when you compare two numbers, even if they are of type int.