Editor

Calculate the Total Cost

Beginner · Write the code · from Python Numbers: Integers, Floats, and Math You'll Actually Use

From the lesson: Python Numbers: Integers, Floats, and Math You'll Actually Use

You're splitting a restaurant bill with three friends. The total is $85. How much does each person owe? You grab your phone calculator, but a Python programmer just types 85 / 4 and gets the answer instantly.

Read the lesson

You're buying items at a store. Calculate the total cost and print it.

  • 3 notebooks at $4.50 each
  • 2 pens at $1.25 each
  • Print the total in this exact format:

    Total: $16.0
    # Item prices and quantities
    notebook_price = 4.50
    notebook_qty = 3
    pen_price = 1.25
    pen_qty = 2
    # Calculate the total cost
    # Print the result

    More Numbers exercises

    All Python exercises · 50 practice problems · Python Fundamentals quiz