WorksheetsCB30: Unit 2 TEST Review
Total questions: 34
Worksheet time: 26mins
Which line of code outputs the decimal portion of a float stored in the variable x?
print(x / 1000)
print(x - int(x))
print(x)
print(x % 1000)
Three of the following values could be stored as strings. When would you NOT use a string command?
To store a list of colors
To store decimal values
To store a word
To store values NOT used for calculations
Consider the following code:
x = int(input("Enter a number: "))
print (x)
What happens if the user types in A?
It prints 65
It prints A
This would cause an error: an integer variable cannot store a string.
This would cause an error: int and input cannot be used together in the same line
Which of the following is NOT a data type in Python?
float
string
decimal
integer
Which of the following numbers might this code generate: random.randint(1,9)?
10
1
11
0
What is NOT a built-in function in python?
sqrt()
string()
fabs()
print()
To generate numbers between and including -10 to 10 you would use:
random.random()*20 + -10
randint(-10, 10)
random.random(-10, 10)
random.randint(-10, 10)
Consider the following code:
a = 3
b = 2
print (a ** b)
What is output?
1
6
8
9
What is output?
print (12 % 5)
0
1
2
5
Consider the following code:
x = 9
y = -2
z = 2
print (x + y * z)
What is output?
5
9
13
14
You need to find the square root of a value. Which of the following functions would you use?
int
sqrt
fabs
pow
You need to make sure a number the user types in is non-negative. Which of the following functions would you use?
abs
fabs
pos
int
Consider the following code:
x = 5
x = x * 3
print (x)
What is output?
5
15
27
75
The following code is intended to find the average of three numbers entered from the keyboard. What is wrong with the code?
print ("Enter 3 numbers: ")
n1 = float(input ("Enter a number: "))
n2 = float(input ("Enter a number: "))
n3 = float(input ("Enter a number: "))
print (n1 + n2 + n3 /3)
n1, n2, and n3 should use the str command
The code is missing parentheses around n1 + n2 + n3 in the last line
Nothing, it correctly finds the average of the numbers.
Nothing, it correctly finds the sum of the numbers
What is the output for the following?
x = 7
print ("The number is: " + x * 2)
14
The number is: 14
The number is: x
None, there is an error
Which of the following calculates to 10?
3 * 6 + 2 /2
(3 * 6) + 2 /2
(3 * 6 + 2) /2
3 * (6 + 2 /2)
Which of the following would be the best variable name to store the value of your English letter grade?
g
LG
1grade
letter_Grade
Why can it be helpful to perform mathematical calculations using programming? Choose the best answer.
Because is an important skill
Because computers can quickly do calculations much larger and complex than humans
Because the values stored in variables cannot change
Because computers are used to store digital data, not analog.
Consider the following code:
x = 19
y = 5
print (x % y)
What is output?
2
3
4
sqrt
Consider the following code:
print (min("whom", "carton", "landform", "composite", "apron", "deposit", "become"))
What is output?
apron
become
carton
whom
What is output?
x = -2
y = 3
print (x + y * 2)
-2
3
4
8
What is output by the following?
print(6 % 8)
5
6
7
8
What is output by the following?
print(10 % 3)
0
1
2
3
Which of the following correctly stores 45 squared in the variable x?
x = 45 ^ 45
x = 45 ** 2
x = 45 * 2
x = 45 ** 45
What is output?
x = 9
y = -3
z = 2
print(x + y * z)
-3
3
6
9
What is wrong with the following code? There may be more than one answer.
n1 = input("Enter a number: ")
n2 = input("Enter a number: ")
n3 = input("Enter a number: ")
print ("The average is: " + str( n1 + n2 + n3 /3))
It is missing ( ) in the last line to correctly calculate the average
There should be a float function on the input commands.
It is missing a pow in the last line to correctly calculate the average.
Nothing, it correctly finds the average of the numbers
To input a decimal you need the ____________ function.
float
int
str
val
