PYTHON CORE · LESSON 12

Number from response

Turn the text into a number · about 12 minutes

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

Response input - text

Even if you write 4, input will return the text. Turn it into an integer using int.

age = int(input("Сколько лет? "))

✦ Now age can be added to the numbers.

STEP 2

Calculate after entering.

First get a number, then use the usual + sign. Brackets help to see the order of action.

age = int(input("Сколько лет? "))
print(age + 1)

✦ Enter 8 and 9 will appear.

IN-CLASS PRACTICE

Type the code yourself

Type an example manually. Check both pairs of brackets.

year = int(input("Какой сейчас год? "))
print(year + 1)
Open the editor for class work
HOMEWORK

Solve it yourself

Ask a number, save an integer in number, and add 2 more. Think of the text yourself.

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

Opening up your homework