JuaInstitute
Reading

Getting Input and Printing Output

Every useful program needs to take information in and give information back out. In Python, that starts with two functions: input() and print().

print() and f-strings

You've already used print() to show a value. Most real programs need to print a mix of fixed text and variable values together — and the clean, modern way to do that is an f-string:

name = "Amara"
age = 24

print(f"{name} is {age} years old.")
# Amara is 24 years old.

The f right before the opening quote turns the string into an f-string — anything inside {curly braces} gets evaluated as a real Python expression and inserted into the text. This isn't limited to just variable names:

price = 49.999
print(f"Total: ${price:.2f}")
# Total: $50.00

:.2f inside the braces is a format spec — here, "round this to exactly 2 decimal places, as a fixed-point number." This exact pattern is how real applications display prices, percentages, and measurements correctly instead of showing ugly numbers like 49.999000000001 (a real thing that happens with raw floating-point math).

input() and why it always returns text

input() pauses your program, waits for the user to type something and press enter, and returns whatever they typed — always as a string, even if they typed a number:

name = input("What's your name? ")
print(f"Hello, {name}!")

This next part catches almost every beginner at least once:

age = input("How old are you? ")
next_year = age + 1   # This CRASHES

Even if the user types 24, age holds the text "24", not the number 24 — and Python refuses to add a number to a string. You have to explicitly convert it:

age = input("How old are you? ")
age = int(age)          # now it's a real integer
next_year = age + 1     # works
print(f"Next year you'll be {next_year}.")

int() converts text to a whole number, float() converts text to a decimal number, and str() converts almost anything back into text. You will use this exact pattern — input() then immediately convert — constantly, in nearly every program that takes user input.

Putting it together

name = input("Name: ")
score1 = float(input("Score 1: "))
score2 = float(input("Score 2: "))
average = (score1 + score2) / 2
print(f"{name}'s average score is {average:.1f}")

Four lines, and this is already a genuinely real, working program: it takes real input, does real math, and produces cleanly formatted real output. Every program you'll ever write is built from exactly this same shape — get input, process it, show output — just with more steps in the middle.

This week's practical exercise (leads into the graded assignment)

Before attempting the graded assignment for this week, sketch out the logic on paper: a short program that asks for someone's name and two numbers, then prints a full sentence stating their name and the sum of the two numbers, formatted with an f-string. Get comfortable with the input → convert → use pattern before moving on — the graded exercise (the next lesson, which has a real code editor attached) builds directly on it.

Operators and ExpressionsNext: Practice: Build a Tip Calculator 🔒