Step 1: Money in whole pennies
Sam typed this into the old till for three flat whites at £3.20:
print(3.20 * 3)
and the till answered:
9.600000000000001
A number with a decimal point is a float, and Python keeps floats in binary. Most decimals,
3.20 among them, have no exact binary form, so a sum can come out a hair off. Shops won't have that,
so tills count whole pennies instead: £3.20 is 320. Whole numbers (integers) are always exact.
receipt.py keeps its prices that way:
FLAT_WHITE = 320
CROISSANT = 245
The capitals are a habit, not a rule: programmers write a value the script never changes, like a
price, in capitals so it stands out. Sam's order sits underneath, flat_whites = 2 and
croissants = 1.
Work out the order's total in pennies, keep it in a variable called total (the next steps use it)
and print it:
Total in pennies: 885
* multiplies and + adds, and Python does the multiplying first, the way arithmetic always works.
Press Run, then Check. The check changes the order and the prices and runs receipt.py
again, so the total has to come from the variables.
receipt.py, the file you edit11 lines
# Bean There's till. Prices are in whole pennies: 320 means £3.20.
FLAT_WHITE = 320
CROISSANT = 245
# Sam's order
flat_whites = 2
croissants = 1
# TODO (Step 1): work out the order's total in pennies, keep it in a variable called total,
# and print it:
# Total in pennies: 885