Fizz buzz algorithm

Day 004

Problem statement: Fizz and Buzz refer to any number that’s a multiple of 3 and 5 respectively. In other words, if a number is divisible by 3, it is substituted with Fizz. if a number is divisible by 5, it is substituted with Buzz. If a number is simultaneously a multiple of 3 AND 5, the number is replaced with “Fizz Buzz.”


numbers = [i for i in range(1,21)]

for number in numbers:

    div_by_3 = number%3 == 0
    div_by_5 = number%5 == 0

    if div_by_3 and div_by_5:
        print("%s Fizz Buzz"%(number))
    elif div_by_3:
        print("%s Fizz" % (number))
    elif div_by_5:
        print("%s Buzz" % (number))