Aral Code

Getting Started Lesson 4 of 23

Python print() and input()

Show output with print(), control separators and line endings, ask the user for input with input(), and convert typed text to numbers.

Most programs follow the same pattern: get some input, process it, and show output. In Python, input() gets text from the user and print() shows results.

print()

print("Magandang umaga!")
print(100)
print(15 * 4)
print()               # an empty line
print("Done")

Output

Magandang umaga!
100
60

Done

Printing several things

Separate values with commas. Python puts a space between them automatically:

name = "Ana"
age = 15
print("Name:", name, "Age:", age)

Output

Name: Ana Age: 15

sep and end

sep changes what goes between values, and end changes what goes at the end (normally a new line):

print("2026", "12", "25", sep="-")
print("Loading", end="")
print("...", end="")
print(" done!")

Output

2026-12-25
Loading... done!

f-strings: the best way to print values

Put an f before the quotes and write variables inside curly braces:

name = "Jose"
average = 92.456
print(f"{name}'s average is {average}")
print(f"Rounded: {average:.2f}")
print(f"Next year: Grade {9 + 1}")

Output

Jose's average is 92.456
Rounded: 92.46
Next year: Grade 10

:.2f means "show as a decimal with 2 places". f-strings get their own section in the Strings lesson.

input()

input() shows a message, waits for the user to type and press Enter, then gives back what they typed:

name = input("What's your name? ")
section = input("Section: ")
print(f"Hi {name} of {section}!")

Output

What's your name? Carla
Section: Mabini
Hi Carla of Mabini!

input() always gives a string

Even if the user types a number, input() returns text. Doing math with it causes surprises:

age = input("Age: ")
print(age + 1)

Error

Age: 15
TypeError: can only concatenate str (not "int") to str

Convert the text with int() for whole numbers or float() for decimals:

age = int(input("Age: "))
print(f"Next year you'll be {age + 1}.")

price = float(input("Price: "))
qty = int(input("Quantity: "))
print(f"Total: ₱{price * qty:.2f}")

Output

Age: 15
Next year you'll be 16.
Price: 12.50
Quantity: 4
Total: ₱50.00

A complete mini program

# Jeepney fare calculator
print("=== Jeepney Fare Calculator ===")
km = float(input("Distance in km: "))

base_fare = 13      # first 4 km
extra = max(0, km - 4) * 1.80
fare = base_fare + extra

print(f"Your fare is ₱{fare:.2f}")

Output

=== Jeepney Fare Calculator ===
Distance in km: 9
Your fare is ₱22.00

Input, process, output. Almost every program you'll ever write follows this pattern.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. What type does input() always return?
2. What does print("a", "b", sep="-") show?
3. How do you convert "25" into a whole number?
4. What does f"{3.14159:.2f}" produce?

By Sir Reyel · Last updated 2026-12-04