Skip to content

input() — the program asks you

So far your programs have only talked. Now let’s teach them to listen: input() gets information from the user.

In the example below, Aysel is already written in the “Inputs” box. Open the box and take a look, then run it:

Inputs (for input())

One value per line — read in order by input().

Output
 

input("What's your name? ") — shows the question, takes the answer, and puts it in the name box. Change the name in the Inputs box and run it again!

Here’s the trap. Even if the user types 12, input() returns it as text"12". You can’t do math with text:

Inputs (for input())

One value per line — read in order by input().

Output
 

Run it — you’ll see an error: Python says it can’t add a number to text. The fix: use int() to turn the text into a whole number:

Inputs (for input())

One value per line — read in order by input().

Output
 

The rule is simple: if you need to do math with a number — int(input(...)).

Mission

A program that greets you

+10 XP

Use input() to ask for the user’s name and reply in the form Hello, <name>! (For checking, Tural is already filled in under Inputs.)

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Next year

+15 XP

Ask for an age, add 1, and print the result. Don’t forget the int() conversion! (The Inputs box has 12 — so the answer should show 13.)

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Adding machine

+15 XP

Build your first calculator: the program should ask for two numbers and print their sum. (7 and 5 are ready under Inputs.)

Inputs (for input())

One value per line — read in order by input().

Output
 

🏅 You finished this module! Your programs can now talk, calculate, remember, and listen. In the next module the most exciting part begins: your program will learn to make decisionsif/else. The “right answer / wrong answer” logic in games comes straight from there.