0
0
Intro to Computingfundamentals~20 mins

Conditional logic (if-then decisions) in Intro to Computing - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Conditional Logic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
trace
intermediate
2: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)
AExcellent
BNo output (error)
CNeeds Improvement
DGood
Attempts:
2 left
💡 Hint
Check which condition the score 75 satisfies first.
🧠 Conceptual
intermediate
1: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?
AIt runs only if the if condition is false and no elif conditions are true.
BIt runs regardless of the if condition.
CIt runs only if the if condition is true.
DIt runs only if all conditions are true.
Attempts:
2 left
💡 Hint
Think about when else executes compared to if and elif.
Comparison
advanced
2:00remaining
Compare two conditional expressions
Which option correctly shows two equivalent ways to check if a number is between 10 and 20 inclusive?
A10 <= num <= 20 and num > 10 and num < 20
B10 <= num <= 20
Cnum > 10 or num < 20
Dnum >= 10 and num <= 20 and 10 < num < 20
Attempts:
2 left
💡 Hint
Look for the simplest and correct way to check the range.
identification
advanced
1: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")
AIndentationError due to wrong indentation
BNameError because x is undefined
CSyntaxError due to missing colon after if condition
DNo error, prints output correctly
Attempts:
2 left
💡 Hint
Check punctuation after the if condition.
🚀 Application
expert
2: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)
AMedium Odd
BMedium Even
CLow
DHigh
Attempts:
2 left
💡 Hint
Check the value against each condition and the inner if for even or odd.