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.
First conversation
Section titled “First conversation”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().
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!
Heads up: input() always returns text
Section titled “Heads up: input() always returns text”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().
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().
The rule is simple: if you need to do math with a number — int(input(...)).
Missions
Section titled “Missions”A program that greets you
+10 XP ✓ CompletedUse 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().
Next year
+15 XP ✓ CompletedAsk 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().
Adding machine
+15 XP ✓ CompletedBuild 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().
🏅 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 decisions — if/else. The “right answer / wrong answer” logic in games comes straight from there.