Lesson 9 of 34

elif: More than Two Choices

8 min 25 XP

When there are more than two choices, use elif (else if). Python checks from top to bottom and runs only the first part that is True.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Order matters! Put the biggest limit (>= 35) first, or 40 would also print “Warm”.

Here is a shop discount example. Try different amounts in the Input box.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Challenge

+25 XP

Read marks with input() and print the grade: 90 or more → A 75 or more → B 50 or more → C anything else → Fail

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.