bhylu.com

Advertisements

Output Variables

Display values in a way that makes their meaning obvious. A number without a label is often difficult to interpret when several calculations produce output.

Understand the idea

print accepts mixed arguments and inserts spaces between them. An f-string is useful when the wording needs precise placement or formatting. Both approaches create display text; the original variables keep their values. Choose readable output over squeezing an entire report into one complicated expression.

Where to try it

Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.

A worked example

Python

name = "Mira"
seats = 4
print(name, "reserved", seats, "seats")
print(f"Reservation: {name} / {seats}")

Read the result

Both lines describe the same reservation in different formats. The f-string inserts current values where its expressions appear.

Try one change

Add a total_cents value and display its label without changing the numeric value stored in the variable.