Last active
August 21, 2018 12:42
-
-
Save code-R/f7c5b1ce4e2c98cf174ccb3e8193f425 to your computer and use it in GitHub Desktop.
fizzbuzz
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
class FizzBuzzGenerator(object): | |
"""docstring for Generator.""" | |
fizz_mapper = { | |
3: "fizz", | |
5: "buzz", | |
7: "fooo", | |
} | |
def __init__(self, count=5): | |
self.count = count + 1 | |
def fizz_buzz(self, input): | |
res = [] | |
for k, v in self.fizz_mapper.items(): | |
if input % k == 0: | |
res.append(v) | |
output = " ".join(res) | |
return output or input | |
def run(self): | |
return (self.fizz_buzz(x) for x in xrange(1, self.count)) | |
fbg = FizzBuzzGenerator(105) | |
for i in fbg.run(): | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment