Last active
May 3, 2016 23:26
-
-
Save efexen/ff6bb641cdf3e860f2b108b3263342f8 to your computer and use it in GitHub Desktop.
Second Python FizzBuzz attempt
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 FizzBuzz: | |
rules = { 3: "Fizz", 5: "Buzz" } | |
def __init__(self, start, stop): | |
self.start = start | |
self.stop = stop + 1 | |
def value_for(self, value): | |
output = "" | |
for divisor, outcome in self.rules.iteritems(): | |
if value % divisor == 0: output += outcome | |
return output or str(value) | |
def fizz(self): | |
while self.start < self.stop: | |
yield self.value_for(self.start) | |
self.start += 1 | |
for result in FizzBuzz(1, 100).fizz(): | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment