Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Conditional Statements Quiz

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What will the following code output? y = 7 if y 5 then

a)

if x > 5:

b)

if (x > 5)

c)

if: x > 5

2.

What does this code display? age = 17 if age >= 18: print("Adult") else: print("Minor")

a)

Adult

b)

Minor

c)

Teen

d)

Error

3.

Which keyword is used for multiple condition checking after if?

a)

elseif

b)

elif

c)

else if

d)

then

4.

What is printed by this program? num = 8 if num % 2 == 0: print("Even") else: print("Odd")

a)

Even

b)

Odd

c)

Error

d)

8

5.

Which of the following about if statements is correct?

a)

An if statement must end with a semicolon.

b)

An if statement must end with a colon (:).

c)

if must be written in capitals.

d)

Every if needs an else.

6.

Find the output: marks = 78 if marks > 90: print("A") elif marks > 70: print("B") else: print("C")

a)

A

b)

B

c)

C

d)

78

7.

What operator means "not equal" in Python?

a)

=!

b)

!=

c)

<>

d)

not=

8.

What is the output of this code? value = 0 if value: print("Something") else: print("Nothing")

a)

Something

b)

Nothing

c)

0

d)

Error

9.

The meaning of elif in Python is:

a)

Else after if

b)

Else if

c)

End if

d)

Also if

10.

What is printed by the following? a = 4 b = 10 if a > b: print("A is bigger") else: print("B is bigger")

a)

A is bigger

b)

B is bigger

c)

A and B are equal

d)

Error

11.

When will the else block be executed?

a)

When the if is True

b)

When all if and elif conditions are False

c)

Always

d)

Only when there is an error

12.

Pick the correctly structured if statement:

a)

if (x > 3):

b)

if x > 3

c)

if: x > 3

d)

if x > 3 then:

13.

What will this code display? x = 3 y = 2 if x + y == 6: print("Correct!") else: print("Try again")

a)

Correct!

b)

Try again

c)

6

d)

Error

14.

Identify the mistake: if x = 4: print("Four")

a)

Missing colon

b)

Should use == instead of =

c)

print should be Print

d)

No else block

15.

What is the output? grade = 82 if grade >= 90: print("Grade A") elif grade >= 80: print("Grade B") else: print("Grade C")

a)

Grade A

b)

Grade B

c)

Grade C

d)

82

16.

Which category will this value fall into? temperature = 55 if temperature 20: print("High") elif points > 5: print("Medium") else: print("Low")

a)

High

b)

Medium

c)

Low

d)

Error

17.

Which operator checks both sides are True?

a)

or

b)

and

c)

not

d)

also

18.

Choose the correct if-else format:

a)

if x = 3 then:

b)

if x == 3:

c)

if x == 3 then:

d)

if (x == 3): then

19.

Which output will this code produce? num = 9 if num % 3 == 0: print("Divisible by 3") else: print("Not divisible by 3")

a)

Divisible by 3

b)

Not divisible by 3

c)

Error

d)

9

20.

Select the true statement:

a)

Every if must have an elif.

b)

If statements can be nested.

c)

You can only have one if in a program.

d)

if must always have an else.

21.

What happens when both conditions in an and are true? a = 5 b = 5 if a == 5 and b == 5: print("Both match") else: print("Mismatch")

a)

Both match

b)

Mismatch

c)

5

d)

Error

22.

What does != mean?

a)

Equal

b)

Less than

c)

Not equal

d)

Greater than

23.

When will an elif block be executed?

a)

If the if condition is true

b)

If no if condition is true and the elif condition is true

c)

Always

d)

Only after else

24.

Which of the following is NOT a correct way to generate random numbers?

a)

random.randint(1, 10)

b)

random.choice([1,2,3])

c)

random.random() to get an integer

d)

random.randint(0,5)

25.

What will the following code output? x = 8 if x > 10: print("Big") else: print("Small")

a)

Big

b)

Small

c)

8

d)

Error