Font size
WorksheetsSelection Programming_If condition
Total questions: 15
Worksheet time: 10mins
What is the purpose of an if statement in Python?
Repeat code
Make a decision
Create a list
Exit the program
temperature = 30 if temperature > 25: print("It's hot!") What is printed?
It's cold
It's hot!
Nothing
Error
What will this code print? number = 0 if number > 0: print("Positive") else: print("Not positive")
Which symbol is used for "equal to" in a condition?
=
==
===
:=
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
B
C
D
Choose the correct structure:
if: x > 10
if (x > 10)
if x > 10:
if x > 10
if "a" in "apple": print("Yes") Will this print "Yes"?
What is missing from this code? age = 18 if age >= 18 print("Adult")
Nothing
Colon :
Indent
Semicolon ;
Which keyword lets us check multiple conditions?
If
Else
Ifel
Elif
x = 5 if x > 10: print("Big") else: print("Small")
Choose the correct statement to check if the age is 18 or more:
if age => 18:
if age >= 18:
if age == 18 or more:
if 18 <= age:
3. What will this print?
5 != 3
True
False
Error
None
You want to test if a number is even. What should you write?
if number = 2:
if number % 2 == 0:
if number / 2:
if even:
1. What does > mean in Python?
Less than
Greater than
Equal
Not equal
What type of error will you get if you forget the colon : after if?
SyntaxError
RuntimeError
ValueError
None
