Challenge 3: Parametrized FizzBuzz Test — Possible Solution ==================================================================== import pytest def fizzbuzz(n): if n % 3 == 0 and n % 5 == 0: return "FizzBuzz" elif n % 3 == 0: return "Fizz" elif n % 5 == 0: return "Buzz" else: return str(n) @pytest.mark.parametrize("n, expected", [ (15, "FizzBuzz"), (9, "Fizz"), (10, "Buzz"), (7, "7"), ]) def test_fizzbuzz(n, expected): assert fizzbuzz(n) == expected Running: pytest test_fizzbuzz.py Output: test_fizzbuzz.py::test_fizzbuzz[15-FizzBuzz] PASSED test_fizzbuzz.py::test_fizzbuzz[9-Fizz] PASSED test_fizzbuzz.py::test_fizzbuzz[10-Buzz] PASSED test_fizzbuzz.py::test_fizzbuzz[7-7] PASSED WHY THIS WORKS AS AN ANSWER ------------------------------ fizzbuzz(n) reuses the exact if/elif/else divisibility logic from Course 1, Chapter 3's own FizzBuzz-style challenge, with one change the challenge specifically asks for: return str(n) instead of print(number), since a testable function needs to hand back a value rather than just print one — str(n) reuses the int-to-string conversion covered back in Course 1 to keep every branch's return type consistently a string. @pytest.mark.parametrize("n, expected", [...]) reuses this chapter's own parametrize example structure exactly — a list of tuples, each one becoming a separate, independently pass/fail test run. The four chosen cases deliberately exercise every branch of fizzbuzz's if/elif/else chain: 15 hits the combined "divisible by both" case, 9 hits Fizz-only, 10 hits Buzz-only, and 7 hits neither, falling through to the plain-number case — together they cover the function's full behavior in one test function instead of four separate ones. def test_fizzbuzz(n, expected): receives each tuple's two values as its own n and expected parameters, and assert fizzbuzz(n) == expected reuses the same plain-assert-equality pattern from every earlier test in this chapter, just run four times automatically instead of once.