Input and Output
Read what the user types with input() and format your output neatly.
Programs become far more useful when they react to the person using them. The input() function pauses the program, waits for the user to type something and press Enter, and gives back what they typed as a string.
Python
name = input("What is your name? ")
print("Nice to meet you,", name)
A sample run looks like this (the user typed Riya):
text
What is your name? Riya
Nice to meet you, Riya
Python
age = int(input("Your age: "))
print("Next year you will be", age + 1)
Controlling print()
print() has two useful options. sep sets what goes between values, and end sets what goes at the end instead of a new line.
Python
print("2026", "10", "25", sep="-")
print("Loading", end="")
print("...", end="")
print(" done")
Output
2026-10-25 Loading... done
Formatting numbers
Inside an f-string you can add a format after a colon. This is the easiest way to line up tables and control decimals.
Python
item = "Pen"
price = 12.5
qty = 4
print(f"{item:<8}|{qty:>4}|{price * qty:>8.2f}")
print(f"{'Total':<8}|{'':>4}|{50:>8.2f}")
print(f"Progress: {0.756:.1%}")
print(f"Big number: {1234567:,}")
Output
Pen | 4| 50.00 Total | | 50.00 Progress: 75.6% Big number: 1,234,567
<8means left-align in 8 characters,>4means right-align in 4..2fmeans two decimal places..1%turns a fraction into a percentage.,adds thousands separators.