Skip to content
Kuza Ndoto Academy

Input & Output

Beginner → IntermediateChapter 2 · Page 10 of 563 min readUpdated 15 Nov 2026

Programs become useful when they talk to people. Output means showing information, usually with print(). Input means reading what the user types, with input(). Together they let you build interactive programs such as calculators, quizzes and menus.

Output with print()

You've already used print(). It can take any number of values, separated by commas, and prints them on one line with spaces between them. Each call then moves to a new line.

name = "Faith"
age = 22
print("Name:", name, "| Age:", age)
print(f"{name} will be {age + 1} next year.")
Name: Faith | Age: 22 Faith will be 23 next year.

Changing the separator with sep

The optional sep argument sets what goes between the values (a single space by default).

print("2026", "11", "15", sep="-")
print("a", "b", "c", sep="")
print("Nairobi", "Kisumu", "Mombasa", sep=" → ")
2026-11-15 abc Nairobi → Kisumu → Mombasa

Changing the ending with end

The optional end argument sets what is printed after the last value. By default it is "\n", a new line. Change it to keep the next output on the same line.

print("Loading", end="...")
print("done")
print("No", end=" ")
print("new line here")
Loading...done No new line here

Printing several lines at once

print("""MENU
1. Check balance
2. Buy airtime
3. Exit""")
MENU 1. Check balance 2. Buy airtime 3. Exit

Input with input()

input() pauses the program, shows an optional message called a prompt, waits for the user to type something and press Enter, and then gives back what they typed.

In the sample run below, the user types Achieng:

name = input("What is your name? ")
print(f"Habari, {name}! Karibu.")
What is your name? Achieng Habari, Achieng! Karibu.

Notice the space at the end of the prompt "What is your name? ". Without it, the user's typing would be squashed against the question mark.

Note

In the sample runs on this site, text that the user types is shown in the output as it would appear on screen, straight after the prompt. Your output depends on what you type.

input() always returns a string

This is the single most important fact about input(). Even if the user types digits, you get text. To do maths, convert it first with int() or float().

age = input("How old are you? ")
print(type(age))
How old are you? 20 <class 'str'>
Common mistake

Doing maths directly on input. If age = input(...) and you write age + 1, Python stops with TypeError: can only concatenate str (not "int") to str. Convert the input first: age = int(input("How old are you? ")).

age = int(input("How old are you? "))
print(f"In 5 years you will be {age + 5}.")
How old are you? 20 In 5 years you will be 25.

Converting between types is covered fully on the next page, Type Conversion, including what happens when the user types something that isn't a number.

A complete interactive program

This program asks for an item and its price, then prints a receipt with 16% VAT added. The output shows a sample run.

item = input("Item: ").strip()
price = float(input("Price in KES: "))

vat = price * 0.16
total = price + vat

print("----- RECEIPT -----")
print(f"{item.title()}: KES {price:,.2f}")
print(f"VAT (16%): KES {vat:,.2f}")
print(f"Total: KES {total:,.2f}")
Item: school bag Price in KES: 2500 ----- RECEIPT ----- School Bag: KES 2,500.00 VAT (16%): KES 400.00 Total: KES 2,900.00

Calling .strip() on the input removes accidental spaces before or after what the user typed, a good habit whenever you read text.

Common mistake

Forgetting the brackets when you store input. name = input (no brackets) doesn't ask the user anything; it just makes name another name for the input function itself. Always call it: input().

Key points

  • print() shows values; sep controls what goes between them and end what comes after.
  • input(prompt) shows a prompt, waits for the user and returns what they typed.
  • input() always returns a string; use int() or float() before doing maths.
  • Use .strip() to tidy up text input, and f-strings to format the results.
Up next · Python BasicsType ConversionTurn text into numbers and back again.
→

Tip: use the ← and → keys to move between pages.