1
Hatchling0 / 300 XP
0day streak 0stars
Your Python practice
Mock tests Readiness
More
Guest mode · saved on this device.

User input

input("prompt") shows a prompt, waits for the user to type, and always returns a string.

name = input("Your name: ")
year = int(input("Birth year: "))   # cast to do maths
In this trainer, input is typed for you automatically. Each exercise lists the answers it will give, and your program must read every one of them with input().

See it run

reply = "7"   # in the lesson: reply = input("A number: ")
n = int(reply)
print(reply * 2, n * 2)

Here the typed answer is assigned directly. In the lesson input() would hand you exactly this: text.

Practice user input

Exercise 1

The user will type Ada, then 1815.

  • Store the name in name and print Hello, Ada! (build it with +).
  • Store the year as an int in birth_year.
  • Make age = 2026 - birth_year.

Exercise 2

The user enters Noor, then 3 guests. Read host and integer guests. Compute chairs = guests + 1 for the host too, then print Noor needs 4 chairs. using + and str().

Exercise 3

A walker enters 4.5 kilometres, then 1.5 hours. Read floats distance and hours, compute speed, and print Speed: 3.0 km/h using + and str(). Divide with /: speed = distance / hours.

Free lesson: use the editor to practice it.

Practice

Loading Python…
More
Loading exercise content…
Visualizer Watch your code run line by line

Run your code, then choose Play to follow its execution.

Memory · names → values
Variables appear here as Python creates them.
Output & plots

One-line daily quest