hands-on labIDE in your browser

Boss: The Discount Rulebook

Level 2's boss. Sam's discounts overlap: happy hour, a free cup on big orders, member and student cards, Monday mornings and a floor under every price.

time
40 min
checked steps
3
level
Beginner
setup
None

$29.99a month with Pro

Pro opens all 3 steps of this lab and every other lab. Cancel any time.

no account needed · Pro opens all 3 steps

See Pro plans

The job

Sam has written the café's discounts down as a rulebook, and they overlap: a happy hour, a free cup on big orders, two kinds of card. Your till asks four questions and works out what the customer pays, in the rulebook's order. Then the rulebook grows, and at the end the prices change.

3 steps, each checked when you finish it

A check runs your work at the end of every step. Hints and the full solution are there if you get stuck.

  1. 1

    Phase 1: Three rules

    Boss rules.

    read this step below ↓

  2. 2

    Phase 2: Rules that overlap

    Sam has added two rules, and changed one:

  3. 3

    Phase 3: Monday morning

    Mondays are slow, so Sam has added two rules and is about to change the prices:

Step 1 as it appears in the lab

The lab’s own text. The hint and the solution stay inside the lab.

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
1A flat white costs FLAT_WHITE. In happy hour, 15:00 up to 17:00, it costs HAPPY_PRICE.
2Five cups or more: one cup is free, at the price a cup costs now.
3A 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

what you get

  • An editor and terminal in your browser
  • A check at the end of every step
  • Hints and the full solution
  • Nothing to install or configure

before you start

  • Level 2's quests: comparisons, if, elif, else, and, or, not, match

Part of the Learn Python track

Lab 10 of 15. Learn Python by running a café till: receipts, orders, discounts and the Friday rush. Nothing to install.

Questions about this lab

Can I see the hidden orders?

When a total is wrong, the checker shows that order's answers, what your till printed and what it should print.

How this challenge works

A level's final challenge asks for its skills at once. You get a rulebook and the exact output, and the checker prices orders you can't see, telling you how many totals came out right and what the first wrong one should have been. Each phase adds rules, so the order of your decisions matters.