← Intro to programming with Python

Mini project: tip calculator

Work out a tip, a total and each person's share.

Start this lesson

Splitting a restaurant bill is a perfect job for a program: the steps are always the same, only the numbers change. Work in small steps, each stored in a variable: first the tip, then the total, then the share per person. Small steps are easy to check one at a time.

bill = 40.00
tip = bill * 0.15        # 15 percent
total = bill + tip
print("Tip:", round(tip, 2))
print("Total:", round(total, 2))

A percent is "out of 100", so 15% is 0.15. The program shows Tip: 6.0 and Total: 46.0.

Common mistake: multiplying by 15 instead of 0.15. That makes the tip 15 times the bill!

Check that the answer makes sense: a 15% tip on a 40 dollar bill should be a bit more than 4 dollars, not 600.