wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Selection Programming_If condition

Total questions: 15

Worksheet time: 10mins

Name
Class
Date
1.

What is the purpose of an if statement in Python?

a)

Repeat code

b)

Make a decision

c)

Create a list

d)

Exit the program

2.

temperature = 30 if temperature > 25: print("It's hot!") What is printed?

a)

It's cold

b)

It's hot!

c)

Nothing

d)

Error

3.

What will this code print? number = 0 if number > 0: print("Positive") else: print("Not positive")

4 lines
4.

Which symbol is used for "equal to" in a condition?

a)

=

b)

==

c)

===

d)

:=

5.

What is the output? score = 75 if score >= 90: print("A") elif score >= 80: print("B") elif score >= 70: print("C") else: print("D")

a)

A

b)

B

c)

C

d)

D

6.

Choose the correct structure:

a)

if: x > 10

b)

if (x > 10)

c)

if x > 10:

d)

if x > 10

7.

if "a" in "apple": print("Yes") Will this print "Yes"?

4 lines
8.

What is missing from this code? age = 18 if age >= 18 print("Adult")

a)

Nothing

b)

Colon :

c)

Indent

d)

Semicolon ;

9.

Which keyword lets us check multiple conditions?

a)

If

b)

Else

c)

Ifel

d)

Elif

10.

x = 5 if x > 10: print("Big") else: print("Small")

4 lines
11.

Choose the correct statement to check if the age is 18 or more:

a)

if age => 18:

b)

if age >= 18:

c)

if age == 18 or more:

d)

if 18 <= age:

12.

3. What will this print?

5 != 3

a)

True

b)

False

c)

Error

d)

None

13.

You want to test if a number is even. What should you write?

a)

if number = 2:

b)

if number % 2 == 0:

c)

if number / 2:

d)

if even:

14.

1. What does > mean in Python?

a)

Less than

b)

Greater than

c)

Equal

d)

Not equal

15.

What type of error will you get if you forget the colon : after if?

a)

SyntaxError

b)

RuntimeError

c)

ValueError

d)

None