NEW
Font size
WorksheetsPython Unit 3 Comprehension Check (3,4,5,6)
Total questions: 20
Worksheet time: 10mins
What is the final result of the expression 4 + 5 * 3?
27
12
21
19
Suppose you have a variable defined as a="4".
What is the variable type of a?
str
int
float
number
What kind of data does a float variable contain?
whole numbers
words
numbers with decimal components
a float is not a Python variable type
What is the final result of the expression 2**3?
6
8
2
that is not a valid Python expression
What is the character that in-line Python comments begin with?
#
%
-
"
What is the output of the following program? Assume the user enters "Florence" then "Fernandez".
Fernandez Florence
Florence
Fernandez
FlorenceFernandez
Florence Fernandez
Which of the following choices is NOT a Python variable type?
int
str
float
number
What will print to the screen when the following program is run?
5
False
<type 'int'>
<type 'bool'>
What will be the output of this program?
5
5
7
5
7
8
5
8
What does this program print?
You are below average height
You are above average height
You are average height
You are below average height
You are above average height
What will be the output of the following program?
12
code
4
codecodecode
What will be the output of the following program?
Tracy
hello Turtle
Turtle
hello Tracy
What is the purpose of exceptions?
To indicate that something has gone wrong, and the program does not know how to continue
To point out when the programmer has written exceptionally good code
To tell the users that he/she has given bad data, such as a negative number instead of a positive number
To allow the programmer to write bad code, but have it still work
Why do programmers use try and except statements when their code might throw an exception?
So that the programmer can disregard the exception and do what he/she wants anyways
because Python requires it
To handle exceptions gracefully and either handle the error or print out a useful error message
Exceptions are only thrown out when there are try and except statements. Otherwise the program fails.
Which of the following for loops will print the following:
0
1
2
3
4
5
for i in range(5):
print(i)
for i in range(1,5,1):
print(i)
for i in range(6):
print(i)
for i in range(0,5,1):
print(i)
Which of the following for loops will print the following:
3
5
7
9
for i in range(3,10,2):
print(i)
for i in range(3,9,2):
print(i)
for i in range(9):
print(i)
for i in range(3,9):
print(i)
What is the value of num when this loop completes?
num=0
for i in range(2, 8, 2):
num = num + i
2
8
12
20
Which of the following for loops will give the same value for i as the loop below?
for i in range(10):
for i in range(11, 0):
for i in range(10,0,-1):
for i in range(0, 10):
for i in range(0,11,1):
When would a while loop be a better control structure to use than a for loop?
When you need to repeat multiple commands
When you need to repeat something 5 times
When you don't know how many time something will repeat
When the user is inputting how many times to repeat something
Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?
for i in range(0, 5):
for i in range(5):
for i in range(0,5,1):
for i in range(5,0,1):
