Skip to content

Instantly share code, notes, and snippets.

@efexen
Last active May 2, 2016 21:43
Show Gist options
  • Save efexen/9b85794137fda020b5d376e862474ad1 to your computer and use it in GitHub Desktop.
Save efexen/9b85794137fda020b5d376e862474ad1 to your computer and use it in GitHub Desktop.
First Python FizzBuzz (Day 2 of Python May)
class FizzBuzz:
def __init__(self, start, stop):
self.start = start
self.stop = stop + 1
def value_for(self, value):
output = ""
if value % 3 == 0:
output += "Fizz"
if value % 5 == 0:
output += "Buzz"
if len(output) == 0:
output = str(value)
return output
def fizz(self):
results = []
for candidate in range(self.start, self.stop):
results.append(self.value_for(candidate))
return results
fizzer = FizzBuzz(1, 100)
for result in fizzer.fizz():
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment