elif — Easy Playground
Short for 'else if'; adds another condition to an if chain
Python Playground
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
elif score >= 60:
grade = "D"
else:
grade = "F"
print(f"Score {score} = Grade {grade}")
# Temperature ranges
temp = 22
if temp < 0:
print("Freezing")
elif temp < 10:
print("Cold")
elif temp < 20:
print("Cool")
elif temp < 30:
print("Warm")
else:
print("Hot")
Output
Click "Run" to execute your code
elif (else if) lets you test multiple conditions in sequence. Only the first matching branch runs.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?