python example
FizzBuzz in Python
Print 1 to 20 with Fizz, Buzz, and FizzBuzz. Run this Python example online with no signup.
Check multiples of 15 first, then 3, then 5. That order avoids printing only Fizz or only Buzz for 15.
print() sends each line to Output. Change the range and Run again.
for n in range(1, 21):
if n % 15 == 0:
print("FizzBuzz")
elif n % 3 == 0:
print("Fizz")
elif n % 5 == 0:
print("Buzz")
else:
print(n)