Week 1 — Environment & Language Basics · ~150 min
Weekly project: a validated order calculator
ProjectFree previewThe brief
Write week1/order_calculator.py — a script someone at a shop counter could run to price an order line. The point is not the multiplication. The point is that bad input never produces a number: it produces a clear message.
Example session:
=== ORDER LINE CALCULATOR ===
Category (Books/Stationery): Books
Quantity: 3
Unit price: 10
Discount % (0-50): 10
Category: Books
Quantity: 3
Unit price: 10.00
Gross: 30.00
Discount: 10.0% (-3.00)
Net: 27.00
And a bad run:
Quantity: three
Quantity must be a whole number greater than 0. You typed: 'three'
Requirements
- Reads category, quantity, unit price and discount % with
input() - Category must be exactly
BooksorStationeryafter.strip()and.title()— so" books "is accepted asBooks; anything else prints a message and stops - Quantity must be a whole number > 0 (use
.isdigit()and a comparison) - Unit price may have decimals. Validate it with this check: remove one dot with
.replace(".", "", 1)and test.isdigit()on the result - Discount must be a whole number from 0 to 50 inclusive
- Every validation failure prints what was expected and what was typed, then stops (no traceback)
- Money shows 2 decimals; the discount shows as a percentage with 1 decimal
- At the top, a comment block lists the validation rules in plain English
- A test log: a markdown or text file with at least 8 runs — 3 valid, 5 invalid (empty input, text, zero quantity, discount 51, price
1.2.3) — showing input and output
You haven't learned loops yet. It's fine for the program to stop after one order or after the first invalid value. Use exit() or nested if/else, whichever you can explain.
Submit
A link to a folder with order_calculator.py and test_log.md. In your notes, describe the input you think is most likely to slip through your validation.
Acceptance checklist
- Runs with
python order_calculator.pyon a fresh terminal - All valid test cases give correct maths (the reviewer recomputes one by hand)
- Every invalid case prints a helpful message, never a traceback
" books "is accepted;"Book"is rejected- The student can explain why
input()values need conversion and why validation happens before conversion
Rubric
Correctness 35% · validation and boundary cases 25% · output and formatting 20% · readability (names, comments, test log) 20%.
Sign in to submit your work.