MyMisPal
← Python lessons
Lesson 4 of 13

Reading input

input() pauses the program until the user types something. In the editor here a box appears inside the output: type in it and press Enter.

PYTHON
name = input("What is your name? ")
print(f"Welcome, {name}!")
Watch outinput() always returns text, even when you type a number, so "5" + "5" gives 55, not 10. Convert with int() or float().
PYTHON
hours = float(input("Hours worked: "))
rate = float(input("Rate per hour: "))
print(f"Pay: {hours * rate:.2f}")

Exercises

Exercise 1

Read two whole numbers (one input each) and print their sum.

Exercise 2

Read a name, then a score, and print for example: Sara scored 95.

Spotted a mistake on this page, or have an idea to improve the site?