Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Unit 1 Post Test: Basic Python

Total questions: 10

Worksheet time: 15mins

Name
Class
Date
1.

Which of the following is the correct syntax to display "Hello, World!" in Python?

a)
echo 'Hello, World!'
b)

print("Hello World!")

c)

console.log("Hello, World!")

d)

print("Hello, World!")

2.

What is the correct way to create a variable in Python and assign the value 10 to it?

a)

int x = 10

b)

var x = 10

c)

num = 10

d)

x := 10

3.

What will be the output of the following code?
print(4 + 5 * 2)

a)
20
b)
12
c)
9
d)
14
4.

Which of the following is an example of type conversion in Python?

a)

x = str(5)

b)

x = int("5")

c)

x = float("3.14")

d)

All of the above

5.

What does the following code output?

name = "John"

age = 25

print("My name is " + name + " and I am " + str(age) + " years old.")


a)

My name is John and I am 25 years old.

b)

My name is John and I am age 25.

c)

My name is name and I am age 25 years old.

d)

Error

6.

What will the following code output if the user inputs "5"?

a)

<class 'int'>

b)

<class 'str'>

c)

<class 'float'>

d)

Error

7.

Which of the following is the correct way to get user input in Python and store it as an integer?

a)

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

b)

user_input = input("Enter a number: ")

c)

user_input = float(input("Enter a number: "))

d)

user_input = eval(input("Enter a number: "))

8.

What will be the result of the following code?

x = 10
y = 3
print (x - y)

a)
7
b)
8
c)
6
d)
5
9.

Which of the following concatenates the string "Python" and the number 3.0?

a)

print("Python" + str(3.0))

b)

print("Python" + 3.0)

c)

print("Python" + int(3.0))

d)

print("Python" + float(3.0))

10.

Which of the following is a valid way to convert a float to an integer in Python?

a)

x = int(3.7)

b)

x = float(3.7)

c)

x = str(3.7)

d)

x = bool(3.7)