1 of 1 ·input()

Lesson 1 · Python Foundation
Getting information from the user.
Input & Interaction
input() asks the person using a program to type something. Begin by asking for a made-up name and printing a greeting. Convert text to a number before doing sums with it.
Click to zoomEverything you've written in Python so far does exactly the same thing every run. Useful for practice, boring as a program.
input() changes that. It stops the program, waits for the user to type something, and hands back what they typed:
name = input("What's your name? ")
print("Hello,", name)
This is the input step from Chapter 1, appearing in your own code for the first time.
Click to zoomHere's the thing that catches every single beginner, and now you're ready for it.
Whatever the user types, input() returns it as a string. Even if they type 25, you get "25" — text.
So this looks right and fails:
age = input("Your age? ")
print(age + 5) # TypeError!
You learned the fix last chapter — convert it:
age = int(input("Your age? "))
print(age + 5) # works
The int() wraps around the input(), converting the moment it arrives.
8 more parts in this lesson
Walkthroughs, code labs, mini-games and the checkpoint quiz unlock when you buy the course.