When you split a takeaway bill, where do the brackets go so you share the whole bill?
You and three friends in Leeds order a takeaway. There’s a discount and a delivery charge. You want to split the whole bill equally. Where would you put the brackets so your code shares the whole bill?
A variable is a name you can use to look up a stored value. Here you store four meals and a price of three pounds fifty per meal. Then you store a two pound discount, a delivery charge of one pound fifty and four people.
First, multiply the quantity by the price to get the cost of all the meals. Python uses a star for multiplication. Then subtract the order discount once and add the delivery charge once. The brackets show that the quantity and price are multiplied together.
The price is for one meal. The discount and delivery charge each apply once to the whole order. Which Python expression gives the total bill? Pick the expression that uses all three operations correctly.
First, calculate and store the total. Then divide it by the number of people. The slash does real division, so you can get a fractional share. To do both calculations in one expression, put brackets around the whole bill before the slash.
Four meals at three pounds fifty come to fourteen pounds. Take off the two pound discount, then add one pound fifty for delivery. The total is thirteen pounds fifty. Divide that by four to get three point three seven five pounds per person before rounding.
Three meals cost four pounds each. You get two pounds off the order and pay one pound for delivery. Four people split the bill. Calculate the share per person and pick an answer.
Your calculated share was three point three seven five pounds. If you round it to three pounds thirty-eight and multiply by four, you get thirteen pounds fifty-two. If you keep the unrounded share and multiply by four, you get the original thirteen pounds fifty.
Your bill is one thousand three hundred and fifty pence. If you give each of four people the same number of whole pennies, Python’s double slash gives three hundred and thirty-seven pence each. That’s integer division. The percent sign gives the remainder: two pennies are left over.