Fix the Bug: Wrong Division
Beginner · Fix the bug · 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 lessonThis code is supposed to split 10 pizzas equally among 3 groups and report how many are left over. But it's using the wrong division operators!
Fix the code so the output is:
Each group gets 3 pizzas
Leftover pizzas: 1total_pizzas = 10
groups = 3
# Bug: using the wrong division operators
pizzas_each = total_pizzas / groups
leftover = total_pizzas / groups
print(f"Each group gets {pizzas_each} pizzas")
print(f"Leftover pizzas: {leftover}")
More Numbers exercises
- Calculate the Total CostBeginner
- Even or Odd CheckerBeginner
- Fahrenheit to Celsius ConverterBeginner
- Predict the OutputBeginner
- Compound Interest CalculatorBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz