Recall & Review
beginner
What is an
elif ladder in Python?An
elif ladder is a way to check multiple conditions one after another. It lets the program choose only one block of code to run based on the first true condition.Click to reveal answer
beginner
How does Python decide which block to execute in an
elif ladder?Python checks each condition from top to bottom. It runs the code for the first condition that is true and skips the rest.
Click to reveal answer
beginner
What happens if none of the
if or elif conditions are true and there is an else block?The
else block runs as a default when all previous conditions are false.Click to reveal answer
beginner
Can multiple
elif blocks run in one if-elif-else ladder?No. Only the first true condition's block runs. After that, Python skips the rest.
Click to reveal answer
beginner
Write a simple
if-elif-else ladder to print 'Cold', 'Warm', or 'Hot' based on temperature variable.Example:<br>
temp = 30
if temp < 15:
print('Cold')
elif temp < 25:
print('Warm')
else:
print('Hot')Click to reveal answer
In an
if-elif-else ladder, what happens if the first if condition is true?✗ Incorrect
Python runs only the first true condition's block and skips the rest.
What keyword is used to check multiple conditions after an
if in Python?✗ Incorrect
elif is used to check additional conditions after if.If none of the
if or elif conditions are true, which block runs?✗ Incorrect
The
else block runs when all previous conditions are false.Can more than one
elif block run in a single if-elif-else ladder?✗ Incorrect
Only the first true condition's block runs; the rest are skipped.
What will this code print?<br>
temp = 20
if temp < 15:
print('Cold')
elif temp < 25:
print('Warm')
else:
print('Hot')✗ Incorrect
Since 20 is less than 25 but not less than 15, it prints 'Warm'.
Explain how Python executes an
if-elif-else ladder step by step.Think about the order and how Python stops checking after one true condition.
You got /4 concepts.
Write a simple example using an
if-elif-else ladder to categorize a number as 'negative', 'zero', or 'positive'.Use comparisons like < 0 and == 0.
You got /4 concepts.