wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Basics - recap

Total questions: 18

Worksheet time: 9mins

Name
Class
Date
1.

Which of the following is a valid way to assign the value 1010 to a variable called `distance` in Python?

a)

`distance == 10`

b)

`distance = 10`

c)

`10 = distance`

d)

`distance := 10`

2.

What is the data type of the value `3.14` in Python?

a)

Integer

b)

String

c)

Float

d)

Boolean

3.

Which of the following is the correct way to check if a variable `temperature` is greater than 2020 in Python?

a)

`if temperature > 20:`

b)

`if temperature => 20:`

c)

`if temperature >> 20:`

d)

`if temperature = 20:`

4.

What will be the output of the following code? ```python x = 5 if x < 10: print("Small") else: print("Large") ```

a)

Small

b)

Large

c)

5

d)

Error

5.

Which of the following is a string in Python?

a)

`42`

b)

`"42"`

c)

`42.0`

d)

`True`

6.

What is the result of the following code? ```python count = 0 while count < 3: count = count + 1 print(count) ```

a)

0

b)

1

c)

2

d)

3

7.

Which of the following is the correct way to start a `for` loop that repeats 55 times in Python?

a)

`for i in 1 to 5:`

b)

`for i in range(5):`

c)

`for i = 1; i <= 5; i++:`

d)

`for (i in 5):`

8.

What will be printed by the following code? ```python for i in range(2, 5): print(i) ```

a)

2 3 4

b)

2 3 4 5

c)

3 4 5

d)

2 3 4 5 6

9.

Which of the following is a Boolean value in Python?

a)

`yes`

b)

`True`

c)

`"False"`

d)

`1.0`

10.

What is the value of `result` after this code runs? ```python result = 7 if result == 7: result = result + 3 ```

a)

7

b)

3

c)

10

d)

0

11.

Which of the following statements will create a variable called `weight` and assign it the value 1212 kilograms?

a)

`weight = 12`

b)

`weight == 12`

c)

`weight := 12`

d)

`12 = weight`

12.

What is the output of the following code? ```python x = 8 if x % 2 == 0: print("Even") else: print("Odd") ```

a)

Even

b)

Odd

c)

8

d)

Error

13.

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

a)

Integer

b)

String

c)

Character

d)

Boolean

14.

How many times will the following loop run? ```python for i in range(4): print(i) ```

a)

3

b)

4

c)

5

d)

0

15.

What is the value of `total` after this code runs? ```python total = 0 for i in range(1, 4): total = total + i ```

a)

3

b)

4

c)

6

d)

7

16.

Which of the following is the correct way to check if a variable score is equal to 100100 in Python?

a)

if score != 100:

b)

if score === 100:

c)

if score = 100:

d)

if score == 100:

17.

What will be the output of the following code?

value = 9
if value > 10:
  print("High")
else:
  print("Low")

a)

9

b)

Error

c)

Low

d)

High

18.

How many times will the following loop execute?

for i in range(2):
  print(i)

a)

1

b)

2

c)

3

d)

0