Getting User Input
Ask for input with input() and use what the user types. The moment your programs stop being one-way and start having conversations.
"The moment you add input() to your program, it stops being a script and starts being a conversation."
— ShurAIWhat is input()?
Until now, every value in your programs was fixed — you wrote it yourself in the code. But real programs need to respond to the person using them. input() pauses the program, shows a message to the user, waits for them to type something and press Enter, then gives that text back to your program.
# The simplest input — show a prompt, store what user types
name = input("What is your name? ")
print(f"Hello, {name}!")
What is your name? Riya
Hello, Riya!
The text inside input() is the prompt — what the user sees before they type. Notice the space at the end of "What is your name? " — this keeps the cursor away from the prompt text. Without it, the user types right next to the question mark which looks cramped.
input() Always Returns a String
This is the most important rule about input() and the source of the most common beginner mistake. No matter what the user types — a number, a date, anything — Python always gives it back as a string.
age = input("How old are you? ")
print(type(age)) # <class 'str'> — always a string!
print(age) # 22 (looks like a number, but it is text)
# This will CRASH — cannot add string + integer
# print(age + 1) ← TypeError!
Trying to do maths with a number the user typed — without converting it first. age + 1 crashes because age is the string "22", not the number 22. You must convert it using int() or float().
Converting Input to Numbers
Wrap input() inside int() or float() to get a number you can do maths with:
# Convert to int — for whole numbers
age = int(input("How old are you? "))
print(f"In 10 years you will be {age + 10}.")
# Convert to float — for decimals
height = float(input("Your height in metres? "))
print(f"Height: {height:.2f}m")
# Two numbers — add them
a = int(input("First number: "))
b = int(input("Second number: "))
print(f"Sum = {a + b}")
How old are you? 22
In 10 years you will be 32.
Your height in metres? 1.75
Height: 1.75m
First number: 15
Second number: 27
Sum = 42
Asking Multiple Questions
Call input() multiple times — each call waits for one answer:
# Registration form example
print("=== Create Your Account ===")
name = input("Full name : ").strip().title()
email = input("Email address: ").strip().lower()
age = int(input("Your age : "))
city = input("Your city : ").strip().title()
print()
print("=== Account Summary ===")
print(f"Name : {name}")
print(f"Email : {email}")
print(f"Age : {age}")
print(f"City : {city}")
=== Create Your Account ===
Full name : sneha kulkarni
Email address: SNEHA@gmail.COM
Your age : 24
Your city : pune
=== Account Summary ===
Name : Sneha Kulkarni
Email : sneha@gmail.com
Age : 24
City : Pune
Notice how input(...).strip().title() cleans the input immediately in one line — strip removes stray spaces, title fixes capitalisation. You do not need to save the raw input first. This is a very common real-world pattern.
Using Input in Conditions
Once you have input, you can use it just like any other variable — in if-statements, comparisons, calculations:
password = input("Enter password: ")
if password == "shurai123":
print("Access granted! Welcome.")
else:
print("Wrong password. Try again.")
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult. Full access granted.")
elif age >= 13:
print("You are a teenager. Limited access.")
else:
print("You are a child. Parental approval needed.")
Real Example — Personal BMI Calculator
A complete interactive program using everything from this lesson:
# BMI Calculator — fully interactive
print("=== BMI Calculator ===")
print()
name = input("Your name : ").strip().title()
weight = float(input("Weight (kg) : "))
height = float(input("Height (m) : "))
# BMI formula: weight / height²
bmi = weight / (height ** 2)
if bmi < 18.5:
category = "Underweight"
elif bmi < 25:
category = "Normal weight"
elif bmi < 30:
category = "Overweight"
else:
category = "Obese"
print()
print(f"Result for {name}")
print(f"BMI : {bmi:.1f}")
print(f"Category : {category}")
=== BMI Calculator ===
Your name : riya
Weight (kg) : 60
Height (m) : 1.65
Result for Riya
BMI : 22.0
Category : Normal weight
What Can Go Wrong — and How to Handle It
If the user types something that cannot be converted, Python raises a ValueError. You will learn to handle this properly with try/except in Topic 50. For now, just be aware it can happen:
# User types "hello" when we expect a number
age = int(input("Enter your age: "))
# If user types "hello" → ValueError: invalid literal for int()
# Safe version using try/except (preview of Topic 50)
try:
age = int(input("Enter your age: "))
print(f"Age: {age}")
except ValueError:
print("Please enter a whole number.")
"input() is where your program opens its eyes and notices the person in front of it. Every useful program eventually needs this."
— ShurAI🧠 Quiz — Question 1
What type does input() always return, no matter what the user types?
🧠 Quiz — Question 2
A user types 25 when your program runs age = input("Age: "). What happens when you try age + 1?
🧠 Quiz — Question 3
How do you ask for a number and immediately make it usable in maths?
🧠 Quiz — Question 4
What does the text inside input("What is your name? ") do?