Skip to content

Instantly share code, notes, and snippets.

@efexen
Last active May 3, 2016 23:26
Show Gist options
  • Save efexen/ff6bb641cdf3e860f2b108b3263342f8 to your computer and use it in GitHub Desktop.
Save efexen/ff6bb641cdf3e860f2b108b3263342f8 to your computer and use it in GitHub Desktop.
Second Python FizzBuzz attempt
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