Skip to content

Instantly share code, notes, and snippets.

@ashwinvis
Created July 29, 2019 20:20
Show Gist options
  • Save ashwinvis/1710f587e6b8f31d416cca13d478b1bd to your computer and use it in GitHub Desktop.
Save ashwinvis/1710f587e6b8f31d416cca13d478b1bd to your computer and use it in GitHub Desktop.
A Fizzbuzz implementation: modular and extensible
lookup = {3: "Fizz", 5: "Buzz"}
def is_multiple(n, m):
return n % m == 0
def fizzbuzz(n):
output = ""
for m, string in lookup.items():
if is_multiple(n, m):
output += string
if not output:
output = str(n)
return output
for i in range(100):
print(fizzbuzz(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment