Editor

FizzBuzz

Beginner · Write the code · from 50 Python Practice Problems with Instant Answer Checking (Beginner to Advanced)

From the lesson: 50 Python Practice Problems with Instant Answer Checking (Beginner to Advanced)

Fifty problems, each with a code editor and real tests. Write your solution, press Check, and see exactly which cases pass. Stuck? Hints reveal one at a time, and the solution unlocks once you have checked at least once. Your code and progress are saved in this browser.

Read the lesson

Write fizzbuzz(n) that returns a list of strings for the numbers 1 to n: "Fizz" for multiples of 3, "Buzz" for multiples of 5, "FizzBuzz" for multiples of both, and the number itself (as a string) otherwise.

fizzbuzz(5)  ->  ["1", "2", "Fizz", "4", "Buzz"]
def fizzbuzz(n):
# Return a list of strings for 1..n
pass
Solution unlocks after your first Check

What Check runs

Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.

RunsExpected output
fizzbuzz(5)['1', '2', 'Fizz', '4', 'Buzz']
fizzbuzz(15)[-1]'FizzBuzz'

More practice problems

All Python exercises · 50 practice problems