Fizz buzz in python with source code

Fizz buzz in python with source code

Introduction

Fizz buzz is a python based programming project. Fizz buzz is a programming exercise to test your programming ability.

Fizz buzz is a python version 3.9 based program. It is a logical program for printing numbers and fizz and buzz from 1 to 100. It is a command line based program. The program uses range function from 0 to 100 that needs to be divided without remainder by 5 and 3. If the ranged number is divided by 5 and 3 it will print fizz buzz.

If the ranged number is divided by 3 it will print buzz and the number divided exactly by 5 will print buzz. We are using for loop and if control statement to get the result. It is a useful programming exercise for beginners. It is simple and easy to understand the basics. This type of python program often comes in an interview. See the code below.

for number in range(0, 100):
    if number % 3 == 0 and number % 5 == 0:
        print("Fizzi Buzze")
    elif number % 3 == 0:
        print("Fizz")
    elif number % 5 == 0:
        print("Buzz")
    else:
        print(number)

Output fizz buzz

fizz buzz

How to use this project?

  • Copy the code and paste in your editor/IDE. (anaconda, pycharm)
  • Execute the program.
  • See the result fizz or buzz or both.