TryBugHunt
pythonLogic errorEasyDay 21 of 30

AI Attempt: FizzBuzz never says FizzBuzz

๐Ÿค– AI Code ReviewSpot the flaw in the AI assistant's solution

An AI assistant wrote this implementation with complete confidence. It passes standard inputs, but fails on a subtle edge case โ€” the exact skill tested in modern AI-assisted interview rounds. Audit the logic, isolate what the model missed, and make it production-ready.

What it should do

An AI assistant wrote this FizzBuzz. fizzbuzz(n) returns "Fizz" for multiples of 3, "Buzz" for multiples of 5, "FizzBuzz" for multiples of both, and otherwise the number as text. Example: fizzbuzz(15) โ†’ "FizzBuzz".

What happens instead

fizzbuzz(15) returns "Fizz". 3, 5 and 7 are right.

def fizzbuzz(n):
    if n % 3 == 0:
        return "Fizz"
    elif n % 5 == 0:
        return "Buzz"
    elif n % 15 == 0:
        return "FizzBuzz"
    return str(n)

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

An easy 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: an if / elif chain stops at the first true condition. Every multiple of 15 is also a multiple of 3, so "Fizz" always wins.

The fix: move the n % 15 == 0 check to the top.

Remember: check the most specific case first.

The pattern behind it: logic errors.

More logic errors to practise

Related errors

Embed this challenge on your site

Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.

<iframe src="https://trybughunt.com/embed/9f85d157-a3c8-4c55-9f52-0055692553b3" title="Debugging challenge: AI Attempt: FizzBuzz never says FizzBuzz" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/9f85d157-a3c8-4c55-9f52-0055692553b3">TryBugHunt</a></p>