Step 1: Phase 1: The first customer
Phase 1: The first customer
Boss rules. One file, till.py. Receipts must match exactly, space for space. From Phase 2 on,
the check serves customers you can't see and tells you how many receipts came out right, and what
the first wrong one looked like. The hint nudges; it won't write the till for you.
The till. Prices are kept in whole pennies, the way tills keep money exact: FLAT_WHITE = 320
means £3.20. Your till asks three questions, in this order: the name, how many flat whites, how
many croissants. Then it prints the receipt. For Sam, two flat whites and one croissant:
Bean There, receipt for Sam
2 x Flat white £6.40
1 x Croissant £2.45
Total £8.85
Thank you, see you tomorrow!
What you need from Level 1:
input("Name: ")asks a question and gives back what was typed, always as text.int(input("Flat whites: "))turns the answer into a whole number.- Work out each amount in pennies (quantity times price) and turn pennies into pounds only when you
print:
f"£{pennies // 100}.{pennies % 100:02d}". The:02dkeeps the zero in £3.05. - The middle lines line up: the description padded to 20 characters on the left, then the amount
right-aligned in 7. In an f-string:
f"{description:<20}{amount:>7}".
Press Run to play Sam at the till: customer.py types Sam's three answers for you. To serve
someone yourself, type python3 till.py in the terminal and answer the questions. Press Check when
the receipt matches. The check serves Sam and one more customer.
till.py, the file you edit6 lines
# Bean There's till. Prices are in whole pennies: 320 means £3.20.
FLAT_WHITE = 320
CROISSANT = 245
# Your till: ask for the customer's name, how many flat whites and how many croissants,
# then print their receipt. The brief on the right shows it exactly.provided for you:customer.py