WorksheetsPython Conditional Statements Quiz
Total questions: 25
Worksheet time: 13mins
What will the following code output? y = 7 if y 5 then
if x > 5:
if (x > 5)
if: x > 5
What does this code display? age = 17 if age >= 18: print("Adult") else: print("Minor")
Adult
Minor
Teen
Error
Which keyword is used for multiple condition checking after if?
elseif
elif
else if
then
What is printed by this program? num = 8 if num % 2 == 0: print("Even") else: print("Odd")
Even
Odd
Error
8
Which of the following about if statements is correct?
An if statement must end with a semicolon.
An if statement must end with a colon (:).
if must be written in capitals.
Every if needs an else.
Find the output: marks = 78 if marks > 90: print("A") elif marks > 70: print("B") else: print("C")
A
B
C
78
What operator means "not equal" in Python?
=!
!=
<>
not=
What is the output of this code? value = 0 if value: print("Something") else: print("Nothing")
Something
Nothing
0
Error
The meaning of elif in Python is:
Else after if
Else if
End if
Also if
What is printed by the following? a = 4 b = 10 if a > b: print("A is bigger") else: print("B is bigger")
A is bigger
B is bigger
A and B are equal
Error
When will the else block be executed?
When the if is True
When all if and elif conditions are False
Always
Only when there is an error
Pick the correctly structured if statement:
if (x > 3):
if x > 3
if: x > 3
if x > 3 then:
What will this code display? x = 3 y = 2 if x + y == 6: print("Correct!") else: print("Try again")
Correct!
Try again
6
Error
Identify the mistake: if x = 4: print("Four")
Missing colon
Should use == instead of =
print should be Print
No else block
What is the output? grade = 82 if grade >= 90: print("Grade A") elif grade >= 80: print("Grade B") else: print("Grade C")
Grade A
Grade B
Grade C
82
Which category will this value fall into? temperature = 55 if temperature 20: print("High") elif points > 5: print("Medium") else: print("Low")
High
Medium
Low
Error
Which operator checks both sides are True?
or
and
not
also
Choose the correct if-else format:
if x = 3 then:
if x == 3:
if x == 3 then:
if (x == 3): then
Which output will this code produce? num = 9 if num % 3 == 0: print("Divisible by 3") else: print("Not divisible by 3")
Divisible by 3
Not divisible by 3
Error
9
Select the true statement:
Every if must have an elif.
If statements can be nested.
You can only have one if in a program.
if must always have an else.
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")
Both match
Mismatch
5
Error
What does != mean?
Equal
Less than
Not equal
Greater than
When will an elif block be executed?
If the if condition is true
If no if condition is true and the elif condition is true
Always
Only after else
Which of the following is NOT a correct way to generate random numbers?
random.randint(1, 10)
random.choice([1,2,3])
random.random() to get an integer
random.randint(0,5)
What will the following code output? x = 8 if x > 10: print("Big") else: print("Small")
Big
Small
8
Error
