EasyPython

Control Flow — FizzBuzz Extended

PythonControl FlowLoops

Implement solve(n) that returns a list of strings for numbers from 1 to n (inclusive) following these rules:

  • "FizzBuzz" if divisible by both 3 and 5
  • "Fizz" if divisible by 3 only
  • "Buzz" if divisible by 5 only
  • The number as a string otherwise

Raise ValueError("n must be positive") if n < 1.

Examples

  • solve(5)["1", "2", "Fizz", "4", "Buzz"]
  • solve(15)[-1] → "FizzBuzz"

Sample tests

Test #1First 5 numbers
Input: [5]
Output: ["1","2","Fizz","4","Buzz"]
Test #2Classic FizzBuzz to 15
Input: [15]
Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
Test #3n=1
Input: [1]
Output: ["1"]