wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CB30: Unit 2 TEST Review

Total questions: 34

Worksheet time: 26mins

Name
Class
Date
1.

Which line of code outputs the decimal portion of a float stored in the variable x?

a)

print(x / 1000)

b)

print(x - int(x))

c)

print(x)

d)

print(x % 1000)

2.

Three of the following values could be stored as strings. When would you NOT use a string command?

a)

To store a list of colors

b)

To store decimal values

c)

To store a word

d)

To store values NOT used for calculations

3.

Consider the following code:

x = int(input("Enter a number: "))

print (x)


What happens if the user types in A?

a)

It prints 65

b)

It prints A

c)

This would cause an error: an integer variable cannot store a string.

d)

This would cause an error: int and input cannot be used together in the same line

4.

Which of the following is NOT a data type in Python?

a)

float

b)

string

c)

decimal

d)

integer

5.

Which of the following numbers might this code generate: random.randint(1,9)?

a)

10

b)

1

c)

11

d)

0

6.

What is NOT a built-in function in python?

a)

sqrt()

b)

string()

c)

fabs()

d)

print()

7.

To generate numbers between and including -10 to 10 you would use:

a)

random.random()*20 + -10

b)

randint(-10, 10)

c)

random.random(-10, 10)

d)

random.randint(-10, 10)

8.

Consider the following code:

a = 3

b = 2

print (a ** b)


What is output?

a)

1

b)

6

c)

8

d)

9

9.

What is output?

print (12 % 5)

a)

0

b)

1

c)

2

d)

5

10.

Consider the following code:

x = 9

y = -2

z = 2

print (x + y * z)


What is output?

a)

5

b)

9

c)

13

d)

14

11.

You need to find the square root of a value. Which of the following functions would you use?

a)

int

b)

sqrt

c)

fabs

d)

pow

12.

You need to make sure a number the user types in is non-negative. Which of the following functions would you use?

a)

abs

b)

fabs

c)

pos

d)

int

13.

Consider the following code:

x = 5

x = x * 3

print (x)


What is output?

a)

5

b)

15

c)

27

d)

75

14.

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)

a)

n1, n2, and n3 should use the str command

b)

The code is missing parentheses around n1 + n2 + n3 in the last line

c)

Nothing, it correctly finds the average of the numbers.

d)

Nothing, it correctly finds the sum of the numbers

15.

What is the output for the following?

x = 7

print ("The number is: " + x * 2)

a)

14

b)

The number is: 14

c)

The number is: x

d)

None, there is an error

16.

Which of the following calculates to 10?

a)

3 * 6 + 2 /2

b)

(3 * 6) + 2 /2

c)

(3 * 6 + 2) /2

d)

3 * (6 + 2 /2)

17.

Which of the following would be the best variable name to store the value of your English letter grade?

a)

g

b)

LG

c)

1grade

d)

letter_Grade

18.

Why can it be helpful to perform mathematical calculations using programming? Choose the best answer.

a)

Because is an important skill

b)

Because computers can quickly do calculations much larger and complex than humans

c)

Because the values stored in variables cannot change

d)

Because computers are used to store digital data, not analog.

19.

Consider the following code:

x = 19

y = 5

print (x % y)


What is output?

a)

2

b)

3

c)

4

d)

sqrt

20.

Consider the following code:

print (min("whom", "carton", "landform", "composite", "apron", "deposit", "become"))


What is output?

a)

apron

b)

become

c)

carton

d)

whom

21.

What is output?

x = -2

y = 3

print (x + y * 2)

a)

-2

b)

3

c)

4

d)

8

22.

What is output by the following?

print(6 % 8)

a)

5

b)

6

c)

7

d)

8

23.

What is output by the following?

print(10 % 3)

a)

0

b)

1

c)

2

d)

3

24.

Which of the following correctly stores 45 squared in the variable x?

a)

x = 45 ^ 45

b)

x = 45 ** 2

c)

x = 45 * 2

d)

x = 45 ** 45

25.

What is output?

x = 9

y = -3

z = 2

print(x + y * z)

a)

-3

b)

3

c)

6

d)

9

26.

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

a)

It is missing ( ) in the last line to correctly calculate the average

b)

There should be a float function on the input commands.

c)

It is missing a pow in the last line to correctly calculate the average.

d)

Nothing, it correctly finds the average of the numbers

27.

To input a decimal you need the ____________ function.

a)

float

b)

int

c)

str

d)

val

28.
Finds the smallest in a set of values. → max
a)
True
b)
False
29.
Gives the remainder of integers which have been divided.
a)
Min
b)
Max
c)
Mod
d)
Modular Division
30.
Collection of commands given a name, ex.: input( )
a)
Operator
b)
Function
c)
Min
d)
Random
31.
Module used to create random numbers in programs. Numbers are not really random.
a)
Min
b)
RGB
c)
Max
d)
Random
32.
Finds the largest in a set of values.
a)
Min
b)
Max
c)
Random
d)
Mod
33.
Data sets that are too large and complex for traditional data processing applications is called Big Data.
a)
True
b)
False
34.
When do you NOT use a String?
a)
To store decimal values. 
b)
To store a word. 
c)
 To store values NOT used for calculations. 
d)
To store color values.