Created
July 29, 2012 20:46
-
-
Save mikedory/3201764 to your computer and use it in GitHub Desktop.
Python FizzBuzz (with a generator)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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