Fizz Buzz Python

Here's my solution to the classic fizz buzz question written in Python.

Print out numbers 1 through 100.
When a number is divisible by 3 replace it with "fizz".
When a number is divisible by 5 replace it with "buzz".
When a number is divisible by both 3 and 5 replace it with "fizz buzz".

First declare the variables i, fizz, and buzz with the values of 0, 3, and 5 respectively.

i = 0
fizz = 3
buzz = 5

To start the logic of the program, declare a while loop that runs as long as i is less than 100. At the beginning of the loop, with every pass-through, add 1 to the value of i.

while i < 100:

    i += 1

The main logic of the program comes in the form of an if elif else statement. The first part of the if statement uses the modulo operator to evaluate the remainder value between the values of i and fizz, and the remainder value between the values of i and buzz. When both remainder values evaluate to 0, the string "fizz buzz" is printed. 

if i % fizz == 0 and i % buzz == 0:
    print("fizzbuzz")

With the next elif part, again the modulo operator evaluates the remainder value between the values of i and fizz. When i and fizz evaluate to 0, the string "fizz" is printed.

elif i % fizz == 0:
    print("fizz")

Once more, the modulo operator evaluates the remainder value between the values of i and buzz. When i and buzz evaluate to 0, the string "buzz" is printed.

elif i % buzz == 0:
    print("buzz")

With the last else part, when neither fizz is divisible by 3 nor buzz is divisible by 5, the value of i is printed. 

else:
    print(i)

Here is what all the code together looks like:

i = 0
fizz = 3
buzz = 5

while i < 100:

    i += 1
    
    if i % fizz == 0 and i % buzz == 0:
        print("fizzbuzz")
    elif i % fizz == 0:
        print("fizz")
    elif i % buzz == 0:
        print("buzz")
    else:
        print(i)