PYTHON CORE · LESSON 15

Two conditions at once.

and · about 13 minutes

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

You need both answers «да»

and combines two checks. The whole condition is true only if both parts are true.

age = 9
print(age > 7 and age < 12)

✦ 9 is greater than 7 and less than 12, so True.

STEP 2

Use with if

In if you can check two things. If one is wrong, else will be executed.

age = 9
if age > 7 and age < 12:
    print("Подходит")
else:
    print("Не подходит")

✦ It'll be right here.

IN-CLASS PRACTICE

Type the code yourself

Dial both checks and indentations. Find the word and.

level = 4
if level > 2 and level < 6:
    print("Можно")
else:
    print("Нельзя")
Open the editor for class work
HOMEWORK

Solve it yourself

Save 10 to age. If age is greater than 7 and less than 13, output «Подходит», otherwise «Не подходит». Use and.

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

Opening up your homework