Skip to content

Instantly share code, notes, and snippets.

@mikedory
Created July 29, 2012 20:46
Show Gist options
  • Save mikedory/3201764 to your computer and use it in GitHub Desktop.
Save mikedory/3201764 to your computer and use it in GitHub Desktop.
Python FizzBuzz (with a generator)
#!/usr/bin/env python
def fizzbuzzerize(numberRange):
for number in numberRange:
if number % 15 == 0:
yield 'Fizzbuzz'
if number % 3 == 0:
yield 'Fizz'
elif number % 5 == 0:
yield 'Buzz'
else:
yield number
def main():
for fizzbuzz in fizzbuzzerize(range(1,101)):
print fizzbuzz
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment