Challenge - 5 Problems
Conditional Logic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ trace
intermediate2:00remaining
Trace the output of nested if-else statements
Consider the following code snippet. What will be the output after running it?
score = 75
if score >= 90:
result = "Excellent"
elif score >= 70:
result = "Good"
else:
result = "Needs Improvement"
print(result)Intro to Computing
score = 75 if score >= 90: result = "Excellent" elif score >= 70: result = "Good" else: result = "Needs Improvement" print(result)
Attempts:
2 left
💡 Hint
Check which condition the score 75 satisfies first.
✗ Incorrect
The score 75 is not >= 90, so the first if is false. The elif checks if score >= 70, which is true, so result is set to "Good". The else block is skipped.
🧠 Conceptual
intermediate1:30remaining
Identify the role of else in conditional statements
Which of the following best describes the role of the
else block in an if-then decision structure?Attempts:
2 left
💡 Hint
Think about when else executes compared to if and elif.
✗ Incorrect
The else block runs only when none of the previous if or elif conditions are true.
❓ Comparison
advanced2:00remaining
Compare two conditional expressions
Which option correctly shows two equivalent ways to check if a number is between 10 and 20 inclusive?
Attempts:
2 left
💡 Hint
Look for the simplest and correct way to check the range.
✗ Incorrect
Option B uses Python's chained comparison which is concise and correct. Other options either add redundant checks or use incorrect logic.
❓ identification
advanced1:30remaining
Identify the error in conditional syntax
What error will this code produce?
if x > 10
print("Greater")
else:
print("Smaller or equal")Intro to Computing
if x > 10 print("Greater") else: print("Smaller or equal")
Attempts:
2 left
💡 Hint
Check punctuation after the if condition.
✗ Incorrect
Python requires a colon ':' after the if condition. Missing it causes SyntaxError.
🚀 Application
expert2:30remaining
Determine the final value after multiple conditions
Given the code below, what is the final value of
status?value = 15
if value > 20:
status = "High"
elif value > 10:
if value % 2 == 0:
status = "Medium Even"
else:
status = "Medium Odd"
else:
status = "Low"
print(status)Intro to Computing
value = 15 if value > 20: status = "High" elif value > 10: if value % 2 == 0: status = "Medium Even" else: status = "Medium Odd" else: status = "Low" print(status)
Attempts:
2 left
💡 Hint
Check the value against each condition and the inner if for even or odd.
✗ Incorrect
Value 15 is not > 20, so first if is false. It is > 10, so the elif block runs. Inside, 15 % 2 is 1 (odd), so status is set to "Medium Odd".