xxxxxxxxxx
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)
# Example usage masih belajar ngoding
fizz_buzz(100)
xxxxxxxxxx
def fizzBuzz(n):
# Write your code here
for i in range(1,a):
if(i%3==0 and i%5!=0):
print("Fizz")
elif(i%5==0 and i%3!=0):
print("Buzz")
elif(i%5==0 and i%3==0):
print(i)
a = int(input("enter the no"))
fizzBuzz(a)
xxxxxxxxxx
output = ""
for i in range(1, 101):
if (i % 3 == 0):
output += "Fizz"
if (i % 5 == 0):
output += "Buzz"
elif (i % 3 != 0):
output += str(i)
output += "\n" # Add a new line at the end of the output
print(output)
xxxxxxxxxx
fizz = 3
buzz = 5
fizzbuzz = fizz * buzz
for i in range(100):
if i % fizzbuzz == o:
print('fizzbuzz')
elif i % fizz == 0:
print('fizz')
elif i % buzz == 0:
print('buzz')
else:
print(i)
xxxxxxxxxx
# changeable game of fizz buzz (all you have to change is n and D
# to add or alter the game.
# No adding or changing if/else required to include bizz at 7 or fuzz at 11
# just insert it into the dictionary. (you could easily make a function out of this)
n = 100
D = {3: 'fizz',
5: 'buzz'}
for x in range(1, n+1): # makes a range as big as we like
out = ''
for k, v in D.items(): # compares each in range with each key in dictionary
if x % k == 0:
out += v # then attaches the associated word onto the output
if not out:
out = x # if the output is still empty, i.e. no listed factors
print(out, end=' ') # the unchanged number becomes the output