wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Basics (CodeHS)

Total questions: 20

Worksheet time: 12mins

Name
Class
Date
1.

What is the final result of the following expression?

5 + 4 * 3 - 1

a)
26
b)
18
c)
13
d)
16
2.

What is the final result of the following expression?

(5 - 3) * 2 - 4

a)
-8
b)
0
c)
12
d)
error
3.

What is the final result of the following expression?

(3 + (8 / 2 - 2)) ** 2

a)
7
b)
error
c)
25
d)
3
4.
Which statement will cause an error?
a)
print("2" + 3)
b)
print(2 * 3)
c)
print(2 * "3")
d)
print("2" * 3)
5.
Which statement will cause an error? The variable name has been previously defined as name = "Susan".
a)
print("Hello" + Susan)
b)
print("Hello", name)
c)
print("Hello " + name)
d)
print(f"Hello {name}")
6.

Based on the following code, what gets printed to the screen?

greeting = 7

name = "Bob"

greeting = "Hello"

print(type(greeting))

a)
7
b)
<class 'int'>
c)
"Hello"
d)
<class 'str'>
7.

Based on the following code, what gets printed to the screen?

greeting = 7

name = "Bob"

greeting = "Hello"

print(greeting)

a)
7
b)
<class 'int'>
c)
"Hello"
d)
<class 'str'>
8.

Suppose you have a variable defined as num = "6". What is the variable type of num?

a)

boolean

b)

integer

c)

string

d)

float

9.

Suppose you have variable x = 4 and y = 2. What will get printed to the screen when this is executed?

print(x / y)

a)

error

b)

0.5

c)

2

d)

2.0

10.

Which choice below correctly prints out the value of the variable?

city = "Searcy"

a)

print(type(city))

b)

print("city")

c)

print("Searcy")

d)

print(city)

11.

What kind of data does an integer contain?

a)

Whole numbers

b)

Letters, special characters, numbers, or words

c)

Numbers with decimal components

d)

True or False

12.

What kind of data does an string contain?

a)

Whole numbers

b)

Letters, special characters, numbers, or words

c)

Numbers with decimal components

d)

True or False

13.

What does the following code print?

x = 3.5

y = 2

print(int(x))

print(x + y)

a)

4

5.5

b)

3

5.5

c)

3

5

d)

4

5

14.

What is the best way to get a number from the user to use in a calculation?

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

15.

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

a)

3

b)

6

c)

1.5

d)

9

16.

What is the appropriate symbol(s) used for in-line comments in Python?

a)

%

b)

#

c)

"""

"""

d)

//

17.

What is the appropriate symbol(s) used for modulus in Python?

a)

%

b)

#

c)

"""

"""

d)

//

18.

Examine the code below. On which line of code will there be an 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

19.

Why does line 2 result in an error?

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

oz_water = weight / 2

a)

weight is a string and cannot be divided

b)

weight is a boolean and cannot be divided

c)

Line 1 does not get input from the user correctly

d)

There is no error

20.

What is the output of the following program? Assume the user enters "John", then "Smith".

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)

John Smith

b)

JohnSmith

c)

Smith John

d)

John

Smith