PYTHON CORE · LESSON 21

Another choice.

elif between if and else · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

When there are more than two options

elif stands for «иначе если». Python will test it when the first if fails.

score = 5
if score > 7:
    print("Супер")
elif score > 3:
    print("Хорошо")

✦ «Хорошо» will appear.

STEP 2

Last option

else will work if no conditions are met. The checks are important.

score = 2
if score > 7:
    print("Супер")
elif score > 3:
    print("Хорошо")
else:
    print("Тренируйся")

✦ «Тренируйся» will appear here.

IN-CLASS PRACTICE

Type the code yourself

Reprint the three branches. Check the indentations.

points = 5
if points > 7:
    print("Высоко")
elif points > 3:
    print("Средне")
else:
    print("Низко")
Open the editor for class work
HOMEWORK

Solve it yourself

Save 6 to score. If score is more than 8, output «Отлично», otherwise if more than 4, «Хорошо», otherwise «Учись». Use if, elif and else.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework