Python Examples
Build a small booking summary using values, functions, and structured records together. Keep the calculation separate from its printed report.
Understand the idea
The input is a list of records with seats and unit prices in cents. A pure total function is easy to test, and the reporting loop handles display. A real application would validate the input shape before calculation. This example intentionally keeps the data inline so it runs online without files or a server.
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
def total(record):
return record["seats"] * record["unit_cents"]
bookings = [{"name": "Mira", "seats": 2, "unit_cents": 1200}, {"name": "Dev", "seats": 1, "unit_cents": 900}]
for booking in bookings:
print(booking["name"], total(booking))
Read the result
Mira's total is 2400 cents and Dev's is 900.
Try one change
Add a third booking and a separate grand-total calculation.