📅  最后修改于: 2022-03-11 14:46:21.601000             🧑  作者: Mango
# 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