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
xxxxxxxxxx
def fizz_buzz(num):
if num % 3 == 0 and num % 5 == 0:
return "fizzBuzz"
elif num % 3 == 0:
return "fizz"
elif num % 5 == 0:
return "buzz"
else:
return num
xxxxxxxxxx
for number in range(1, 101):
if number % 3 == 0 and number % 5 == 0:
print("FizzBuzz")
if number % 3 == 0:
print("Fizz")
if number % 5 == 0:
print("Buzz")
else:
print([number])
xxxxxxxxxx
def fizz_buzz(Ending_number:int):
"""This is a fizz buzz game the starting number would be taken as 1"""
for numbers in range(1,Ending_number):
if numbers % 3 == 0 and numbers % 5 == 0:
print("fizz buzz")
elif numbers % 3 == 0:
print("buzz")
elif numbers % 35 == 0:
print("fizz")
else:
print(numbers)
print(fizz_buzz(120))
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 fizz_buzz(num: int) -> str | int:
if num % 3 == 0 and num % 5 == 0:
return "fizzBuzz"
elif num % 3 == 0:
return "fizz"
elif num % 5 == 0:
return "buzz"
return num
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
def fizzbuzz():
mappings = {3: "Fizz", 5: "Buzz"}
for i in range(1, 101):
words = [mappings.get(j, "") for j in mappings.keys() if i % j == 0]
yield "".join(words) or i
for result in fizzbuzz():
print(result)
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
inputValue = int(input("Enter a Number: "))
if inputValue % 3 == 0 and inputValue % 5 == 0 :
print("fizzbuzz")
elif inputValue % 3 == 0 :
print("fizz")
elif inputValue % 5 == 0 :
print("buzz")
else:
print(inputValue)