Skip to content

Instantly share code, notes, and snippets.

@yassu
Created July 9, 2014 09:17
Show Gist options
  • Save yassu/9ed436a88e5bcd136e2e to your computer and use it in GitHub Desktop.
Save yassu/9ed436a88e5bcd136e2e to your computer and use it in GitHub Desktop.
fizzbuzz
#!/usr/bin/env python3
def fizzbuzz():
""" generator of fizzbuzz """
i = 1
while True:
s = ''
if i % 3 == 0:
s += 'Fizz '
if i % 5 == 0:
s += 'Buzz'
if s == '':
s = str(i)
s = s.rstrip()
yield s
i += 1
if __name__ == '__main__':
from sys import argv
num = argv[1]
num = int(num)
gen = fizzbuzz()
for i in range(num):
print(next(gen), end=', ')
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment