wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Unit 3 Python TEST

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.

What is the final result of the expression 7 / 2 + 6?

a)

0

b)

9.5

c)

9

d)

0.875

3.

Choose the print statement below that will cause an error. Assume that num has the value 6, and name has the value Isabella.

a)

print(name + “:” )

print(num)

b)

print(name + ” wants ” + “num ” + “candies”)

c)

print(name + “: ” + str(num))

d)

print(name + “: ” + num)

4.

Which one of the statements below will cause an error?

a)

ans = “hi” * 8

b)

ans = “hi” + 9

c)

ans = “hi” + “hi” + “hi”

d)

ans = (“a” * 4) + “b”

5.

What does the following program print?

a = "hi"

b = 4

c = a * b


print(class(c))

a)

<class 'str'>

b)

<class 'int'>

c)

<class 'float'>

d)

The program crashes and doesn’t print anything.

6.

Suppose you have a variable defined a = "4". What is the variable type of a?

a)

str

b)

int

c)

float

d)

number

7.

Choose the option that correctly prints out the variable(s).

a)

x = "codehs"

print(int(x))

b)

num = 8

print("num")

c)

name = "Alyx"

age = 32

print(name + "is " + age)

d)

language = "Python"

print("I'm learning " + language)

8.

What kind of data does a float variable contain?

a)

Whole numbers

b)

Words

c)

Numbers that can have decimal components

d)

A float is not a Python variable type

9.

What does the following code print?

x = 3.4

y = 1

print(int(x))

print(x + y)

a)

3.4

4.4

b)

3

4.4

c)

3

4

d)

The code causes an error

10.

Which of the following options is the best way to get a number from the user that you plan to use in a mathematical equation?

a)

num = str(input(“Enter a number: “))

b)

num = number(input(“Enter a number: “))

c)

num = input(“Enter a number: “)

d)

num = int(input(“Enter a number: “))

11.

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

a)

6

b)

8

c)

2

d)

That is not a valid Python expression.

12.

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

a)

#

b)

%

c)

-

d)

"

13.

What is the difference between a binary operator and a unary operator?

a)

A computer can use binary operators, but it cannot use unary operators.

b)

A unary operator needs two things, while a binary operator only needs one.

c)

A binary operator needs two things, while a unary operator only needs one.

d)

Binary operators are used for arithmetic expressions, while unary operators are for strings.

14.

On which line of code will Python error?


weight = input("How much do you weigh? ")

oz_water = weight / 2

print("You should drink " + str(oz_water))

print("ounces of water every day if you weigh " + weight)

a)

Line 1

b)

Line 2

c)

Line 3

d)

Line 4

15.

In what order should these statements be executed in order to get input from the user and print out the result?


A) response = input("Do you like cheese? ")

B) print("You have chosen " + confirm)

C) print("You responded " + response)

D) confirm = input("Are you sure? ")

a)

A, B, C, D

b)

B, C, A, D

c)

A, C, D, B

d)

C, B, A, D

16.

What is the output of the following program? Assume the user enters “Florence”, then “Fernandez”.


first_name = input("What is your first name? ")

last_name = input("What is your last name? ")

whole_name = first_name + last_name

print(whole_name)

a)

Fernandez Florence

b)

Florence

Fernandez

c)

FlorenceFernandez

d)

Florence Fernandez

17.

Which of the following statements is true about print statements?


I. In order to print a string literal, the string must be enclosed in quotes.

II. Each print statement will be printed on its own line.

III. Print statements will not let you print string and number characters in the same statement.

IV. Print statements are how you display text on the screen.

a)

I, IV

b)

II, III

c)

I, II, IV

d)

I, III, IV

18.

Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?

a)

user_age

b)

uSeRaGe

c)

user!age!

d)

1user_age

19.

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

a)

int

b)

str

c)

float

d)

number

20.

Choose the correct declaration of a float variable with the value 3.14.

a)

pi = “3.14”

b)

pi = int(3.14)

c)

pi = 3.14

d)

float pi = 3.14