iq.lab
Python starts when a code cell comes near or you run one
easyLoops and basics target 15 min

Fizz Buzz

In a counting game, players count 1, 2, 3 and so on, but some numbers are said as words. A multiple of 3 is a number that 3 divides with nothing left over, such as 6 or 9, and a multiple of 5 works the same way. A number that is a multiple of both 3 and 5 is said as "FizzBuzz". Any other multiple of 3 is said as "Fizz", and any other multiple of 5 as "Buzz". Every other number is said as itself.

Given a positive integer n, return a list of n strings: what is said for 1, then for 2, and so on up to n. Plain numbers go in the list as strings too, so 7 appears as "7".

Example 1
Inputn = 15Output["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]

15 is a multiple of 3 and of 5, so it is "FizzBuzz", not "Fizz".

Example 2
Inputn = 5Output["1", "2", "Fizz", "4", "Buzz"]

3 is the first multiple of 3, and 5 the first multiple of 5.

Example 3
Inputn = 1Output["1"]
Constraints
  • 1 ≤ n ≤ 104

Plan it first

Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.

⌘+Enter runs 0:00Python starts when a code cell comes near or you run one
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.