Step 1: Phase 1: Three rules
Phase 1: Three rules
Boss rules. One file, till.py. The output must match exactly. From Phase 2 on, the check serves
customers you can't see and tells you how many totals came out right, and what the first wrong one
should have been. The hint nudges; it won't write the till for you.
The till. It already asks four questions: the day, the hour, how many cups and the card
(member or none for now). Then it applies Sam's rulebook, in this order:
| The rule | |
|---|---|
| 1 | A flat white costs FLAT_WHITE. In happy hour, 15:00 up to 17:00, it costs HAPPY_PRICE. |
| 2 | Five cups or more: one cup is free, at the price a cup costs now. |
| 3 | A member card takes 10% off what's left. The discount is rounded down to whole pennies: total // 10. |
Then it prints the total, and what the customer saved compared with paying FLAT_WHITE for every
cup. When they saved nothing, the second line says so instead:
Total: £6.75
You saved £2.85
That's a member's three flat whites on Wednesday at 15:00: 3 × 250 is 750, no free cup, then 10% off (75) leaves 675. Full price would have been 960, so they saved 285.
Total: £3.20
No discounts today
Press Run to serve that member (customer.py answers for them), or type python3 till.py in the
terminal and answer yourself. The check serves them and one more customer, who has both a big order
and a card, so the order of the rules shows.
till.py, the file you edit11 lines
# Bean There's till, Level 2: the discount rulebook. Prices are in whole pennies.
FLAT_WHITE = 320
HAPPY_PRICE = 250
day = input("Day: ")
hour = int(input("Hour: "))
cups = int(input("Cups: "))
card = input("Card: ")
# Your till: apply the rulebook in the brief, in its order, then print the total and what the
# customer saved (or "No discounts today").provided for you:customer.py