PYTHON CORE · LESSON 05

Conditions

If not. · about 13 minutes

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

The program can choose

if stands for «если». If the test is correct, the line below it is executed. At the end of the test, put a colon.

score = 7
if score > 5:
    print("Победа")
The road
Verification7 > 5?AnswerYes.Action.Победа

✦ There are four gaps in front of print: this is indentation.

STEP 2

What if the answer is different?

else stands for «иначе». This part works when the condition is incorrect. It stands without indentation, and the command under it is with indentation.

score = 2
if score > 5:
    print("Победа")
else:
    print("Потренируйся")

✦ There is no victory here, so «Потренируйся» will appear.

IN-CLASS PRACTICE

Type the code yourself

Set an example. After if and else, colons are needed, and inside - indentations.

points = 8
if points >= 5:
    print("Супер")
else:
    print("Ещё раз")
Open the editor for class work
HOMEWORK

Solve it yourself

score points are 8. If there are at least 5, output «Сдано», otherwise «Попробуй ещё». Use if and else.

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

Opening up your homework