Reading Input

The input function reads one line from standard input, which is the text your program receives. It returns that line as a string.

item = input()
quantity = int(input())

print("Item:", item)
print("Quantity:", quantity)

Input:

Notebook
3

Output:

Item: Notebook
Quantity: 3

print("Item:", item) prints two values on one line. A comma separates them, and print puts a space between them.

input() always returns text, even when the user types only digits. So the example converts the quantity with int on the same line that reads it. After that line, quantity is a number, and the rest of the code can use it as one.

Each call to input() reads the next line. In this course, the exercises give your program its input lines. You can pass input a prompt (a message for the user), such as input("Age: "). But that prompt would be printed and checked as part of your output, so the exercises in this course do not use prompts.

Read a name and an age in the exercise, then print a greeting and the age next year.