TryBugHunt
pythonLogic errorMedium

50% off 200 comes to 150

BugFind the bug and fix the code

What it should do

checkout(total, pct) takes pct percent off the total. This project has two files: cart.py and pricing.py. Example: checkout(200, 50) → 100.

What happens instead

checkout(200, 50) returns 150. cart.py only passes the numbers on, so look in pricing.py too.

This project has 2 files. The symptom shows up in cart.py, but the bug can be in any of them. Click a file name to open it.

from pricing import apply_discount

def checkout(total, pct):
    return apply_discount(total, pct)

Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).

⏱️0:00
Hints
🏆 0 hints = Flawless Solve
Think & Test Cooldown
2:00 remaining

Take a moment to read the bug symptom and trace the code with Run & Check before unlocking Hint 1.

Hint 2
Unlocks after Hint 1
Hint 3
Unlocks after Hint 2

This bug belongs to the logic errors pattern

The wrong operator, an inverted condition, a formula the right way round but backwards.

What you'll practise

A medium Python debugging exercise about logic errors: the wrong operator, an inverted condition, a formula the right way round but backwards.

The checks your fix must pass

Signs of this kind of bug

Spoiler: why this bug happens(try it first; the hints get warmer one at a time)

What went wrong: apply_discount does 200 - 50. A 50% discount is 200 - (200 × 50 / 100).

The fix: in pricing.py, return total - total * pct / 100

Remember: the file where you see the wrong answer is not always the file with the bug. Follow the function call.

The pattern behind it: logic errors.

More logic errors to practise

Related errors