Loops and patterns · Python exercise
Print numbers from 1 to n with Fizz, Buzz, and FizzBuzz replacements.
Read a positive integer n. For each number from 1 to n, print Fizz if it is divisible by 3, Buzz if divisible by 5, FizzBuzz if divisible by both, or the number itself otherwise. Print one value per line.
Example 1
Input
5
Output
1 2 Fizz 4 Buzz
Example 2
Input
15
Output
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
How testing works
Your code runs once per test case with that case's standard input. Output is compared after normalising trailing spaces and blank lines at the end. Use input() without a prompt when the exercise expects clean output.
Loading editor…
Press Run tests to execute your code against every input case. Python runs in a Web Worker in your browser.