Created
July 29, 2019 20:20
-
-
Save ashwinvis/1710f587e6b8f31d416cca13d478b1bd to your computer and use it in GitHub Desktop.
A Fizzbuzz implementation: modular and extensible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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