Skip to content

Instantly share code, notes, and snippets.

@jedmitten
Last active August 1, 2017 18:19
Show Gist options
  • Save jedmitten/9b6274b087b4d035dc369d7a908f3ac7 to your computer and use it in GitHub Desktop.
Save jedmitten/9b6274b087b4d035dc369d7a908f3ac7 to your computer and use it in GitHub Desktop.
Trying out a fizzbuzz game
import sys
def get_fizzbuzz(start=1):
if start < 1:
raise ValueError('Cannot start below 1')
start -= 1
while True:
start += 1
if not (start % 3) and (start % 5):
yield 'Fizz'
elif not (start % 5) and (start % 3):
yield 'Buzz'
elif not (start % 5 + start % 3):
yield 'FizzBuzz'
else:
yield start
if __name__ == '__main__':
if len(sys.argv) > 1:
start = int(sys.argv[1])
else:
start = 1
if len(sys.argv) > 2:
end = int(sys.argv[2])
else:
end = 100
if not isinstance(start, int):
raise RuntimeError('You must use an integer as a starting value if you specify one (got {})'.format(start))
if not isinstance(end, int):
raise RuntimeError('You must use an integer as a count if you specify one (got {})'.format(end))
g = get_fizzbuzz(start=start)
for i in range(end - start):
print(next(g))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment