Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Exercises
  3. FizzBuzz

Loops and patterns · Python exercise

FizzBuzz

Print numbers from 1 to n with Fizz, Buzz, and FizzBuzz replacements.

beginner3 testsloopsmoduloconditions

Problem

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.

Input and output

Input
One line containing a positive integer n.
Output
n lines of output.

Constraints

  • 1 ≤ n ≤ 100.

Examples

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.

Your solution3 hidden input checks

Loading editor…

Press Run tests to execute your code against every input case. Python runs in a Web Worker in your browser.

Related exercises

beginner

First n Fibonacci Numbers

Print the first n terms of the Fibonacci sequence on one line.

3 tests
beginner

Multiplication Table

Print the multiplication table for one number from 1 to 10.

3 tests
Previous exerciseFirst n Fibonacci NumbersNext exerciseMultiplication Table