0
0
Pythonprogramming~20 mins

Why conditional statements are needed in Python - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Conditional Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why do we use conditional statements in programs?

Imagine you want a program to decide if you can enter a club based on your age. Why do you need conditional statements for this?

ATo store data like names and ages in a list
BTo repeat the same action many times without checking anything
CTo check if the age meets the club's minimum age and decide what to do next
DTo make the program run faster by skipping all checks
Attempts:
2 left
💡 Hint

Think about how the program can choose different actions based on age.

Predict Output
intermediate
2:00remaining
What is the output of this code using conditional statements?

Look at this Python code. What will it print?

Python
age = 20
if age >= 18:
    print("Allowed")
else:
    print("Not allowed")
ANo output
BAllowed
CSyntaxError
DNot allowed
Attempts:
2 left
💡 Hint

Check if 20 is greater or equal to 18.

Predict Output
advanced
2:00remaining
What does this nested conditional print?

What will this code print when run?

Python
score = 75
if score >= 90:
    print("Grade A")
elif score >= 70:
    print("Grade B")
else:
    print("Grade C")
AGrade B
BGrade C
CGrade A
DSyntaxError
Attempts:
2 left
💡 Hint

Check which condition matches 75 first.

Predict Output
advanced
2:00remaining
What error does this code raise?

What error will this code cause?

Python
age = 18
if age > 18:
    print("Adult")
else:
    print("Not adult")
ASyntaxError
BTypeError
CIndentationError
DNo error, prints "Adult"
Attempts:
2 left
💡 Hint

Look carefully at the if statement syntax.

🧠 Conceptual
expert
2:00remaining
Why are conditional statements essential for program decision making?

Choose the best explanation for why conditional statements are essential in programming.

AThey make programs run faster by avoiding loops.
BThey automatically fix errors in the code.
CThey store large amounts of data efficiently.
DThey allow programs to perform different actions based on different inputs or situations.
Attempts:
2 left
💡 Hint

Think about how programs respond to different situations.