Back

Code Challenge: Tip Calculator

Difficulty  

divider

Objective

Calculate a tip amount and a bill total from a subtotal and a tip percentage.

Terms
  • Subtotal — the cost of your food and drink
  • Tip (gratuity) — additional payment given for a service
  • Total — the sum of the subtotal and the tip

A $10 bill with a 20% tip is a $2 tip and a $12 total. A $25 bill with an 18% tip is a $4.50 tip and a $29.50 total.

Skills to Practice

  • Prompting a user for input
  • Saving user input to variables
  • Converting input to the correct data type
  • Performing arithmetic calculations
  • Formatting custom output using variables

Tasks

  • Create a new Python program named cc-tip-calculator.
  • Prompt the user to enter the bill subtotal.
  • Prompt the user to enter the tip percentage as a whole number — 20 means 20%.
  • Calculate the tip. Formula: Tip = Subtotal × (Percentage ÷ 100)
  • Calculate the total.
  • Display the tip and the total in a clear, formatted way.
  • To always show two decimal places on a dollar amount, look up how string formatting works in Python.

Sample Output

Sample Output
--- Tip Calculator ---
Enter the bill subtotal: 50.00 [Enter]
Enter the tip percentage: 15 [Enter]
Tip amount: $7.50
Total amount: $57.50

Commence Challenge