wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Unit 3 Comprehension Check (3,4,5,6)

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the final result of the expression 4 + 5 * 3?

a)

27

b)

12

c)

21

d)

19

2.

Suppose you have a variable defined as a="4".

What is the variable type of a?

a)

str

b)

int

c)

float

d)

number

3.

What kind of data does a float variable contain?

a)

whole numbers

b)

words

c)

numbers with decimal components

d)

a float is not a Python variable type

4.

What is the final result of the expression 2**3?

a)

6

b)

8

c)

2

d)

that is not a valid Python expression

5.

What is the character that in-line Python comments begin with?

a)

#

b)

%

c)

-

d)

"

6.

What is the output of the following program? Assume the user enters "Florence" then "Fernandez".

a)

Fernandez Florence

b)

Florence

Fernandez

c)

FlorenceFernandez

d)

Florence Fernandez

7.

Which of the following choices is NOT a Python variable type?

a)

int

b)

str

c)

float

d)

number

8.

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

a)

5

b)

False

c)

<type 'int'>

d)

<type 'bool'>

9.

What will be the output of this program?

a)

5

b)

5

7

c)

5

7

8

d)

5

8

10.

What does this program print?

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 will be the output of the following program?

a)

12

b)

code

c)

4

d)

codecodecode

12.

What will be the output of the following program?

a)

Tracy

b)

hello Turtle

c)

Turtle

d)

hello Tracy

13.

What is the purpose of exceptions?

a)

To indicate that something has gone wrong, and the program does not know how to continue

b)

To point out when the programmer has written exceptionally good code

c)

To tell the users that he/she has given bad data, such as a negative number instead of a positive number

d)

To allow the programmer to write bad code, but have it still work

14.

Why do programmers use try and except statements when their code might throw an exception?

a)

So that the programmer can disregard the exception and do what he/she wants anyways

b)

because Python requires it

c)

To handle exceptions gracefully and either handle the error or print out a useful error message

d)

Exceptions are only thrown out when there are try and except statements. Otherwise the program fails.

15.

Which of the following for loops will print the following:

0

1

2

3

4

5

a)

for i in range(5):

print(i)

b)

for i in range(1,5,1):

print(i)

c)

for i in range(6):

print(i)

d)

for i in range(0,5,1):

print(i)

16.

Which of the following for loops will print the following:

3

5

7

9

a)

for i in range(3,10,2):

print(i)

b)

for i in range(3,9,2):

print(i)

c)

for i in range(9):

print(i)

d)

for i in range(3,9):

print(i)

17.

What is the value of num when this loop completes?

num=0

for i in range(2, 8, 2):

num = num + i

a)

2

b)

8

c)

12

d)

20

18.

Which of the following for loops will give the same value for i as the loop below?

for i in range(10):

a)

for i in range(11, 0):

b)

for i in range(10,0,-1):

c)

for i in range(0, 10):

d)

for i in range(0,11,1):

19.

When would a while loop be a better control structure to use than a for loop?

a)

When you need to repeat multiple commands

b)

When you need to repeat something 5 times

c)

When you don't know how many time something will repeat

d)

When the user is inputting how many times to repeat something

20.

Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?

a)

for i in range(0, 5):

b)

for i in range(5):

c)

for i in range(0,5,1):

d)

for i in range(5,0,1):