Python Basics

User Input in Python

input() pauses the program, shows a prompt and waits for the user to type a line and press Enter.

What is User Input?

input() pauses the program, shows a prompt and waits for the user to type a line and press Enter.

Read what the user types with input() and convert it to a number.

When should you use it?

  • Learn Python syntax through a practical example.
  • Build a foundation for larger programming problems.
  • Test an idea quickly without a local setup.

Example code

Run code →
main.py
# input() shows a prompt and returns what the user types, always as a string.
name = input("What is your name? ")

# Convert the text to a number before doing arithmetic with it.
age = int(input("How old are you? "))

print(f"Hello, {name}!")
print(f"In 10 years you will be {age + 10}.")

Expected output

What is your name? Ada
How old are you? 29
Hello, Ada!
In 10 years you will be 39.

How it works

input() always returns a string, so int() turns the age into a number before adding 10. In the online IDE, type your answers in the terminal when the prompts appear.

Change the values and run the program in the CodeUtility online Python compiler without installing Python locally.

Practice exercises

Modify the runnable example with the exercises below to build understanding beyond copying the result.

  1. Change the input and predict the output before running.
  2. Handle empty or invalid input.
  3. Wrap the logic in a function and add more test cases.
Run in Python IDE →

Practice with a challenge

Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.

All challenges