bhylu.com

Advertisements

Python Training

Build a small workshop booking report as a final project. The aim is a trustworthy input-to-output flow with tests, not a collection of unrelated snippets.

Understand the idea

Use functions for validation and calculation, records for bookings, and a separate display layer. Reject invalid seat counts, keep monetary units consistent, and define missing-field behaviour. Add JSON import only after the in-memory function is tested. Optional local extensions can save a file or use a lab database with parameterised operations.

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.

Your task

Build a small workshop booking report as a final project. The aim is a trustworthy input-to-output flow with tests, not a collection of unrelated snippets.

Show the worked solution
Python

def booking_total(bookings):
    return sum(item["seats"] * item["price_cents"] for item in bookings)

data = [{"seats": 2, "price_cents": 1200}, {"seats": 1, "price_cents": 900}]
print(booking_total(data))

Check the result

The starting project total is 3300 cents.

Test one more case

Add tests for empty input, one booking, invalid quantities, and a record with a missing field.