You can download this code by clicking the button below.
This code is now available for download.
Print numbers from 1 to n, if a number is divisible by both 3 and 5, print 'FizzBuzz'; if it is only divisible by 3, print 'Fizz'; if it is only divisible by 5, print 'Buzz'; otherwise, print the number itself.
Technology Stack : math, random
Code Type : Function
Code Difficulty : Intermediate
import math
import random
def fizz_buzz(n):
for i in range(1, n+1):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)