Fizz Buzz Program in Python

for i in range(1,30):
if(i%3==0 and i%5==0):
print("Fizz-Buzz")
elif(i%3 == 0):
print("Fizz")
elif(i%5 == 0):
print("Buzz")
else:
print(i)

Output:

Fizz Buzz Program in Python

FizzBuzz Program in Python using function:

 

class Test(object):
def fizzBuzz(self, n):
"""
:type n: int
:rtype: List[str]
"""
result = []
for i in range(1,n+1):
if i% 3== 0 and i%5==0:
result.append("Fizz-Buzz")
elif i %3==0:
result.append("Fizz")
elif i% 5 == 0:
result.append("Buzz")
else:
result.append(str(i))
return result
obj = Test()
print(obj.fizzBuzz(50))

 

Output:

FizzBuzz Program in Python

Leave a Reply

Your email address will not be published. Required fields are marked *