Created
January 16, 2018 13:52
-
-
Save muzhig/dac900485fe8b8b9c2a3605cb02d46d3 to your computer and use it in GitHub Desktop.
Fizzbuzz
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
import itertools | |
def fizzbuzz(): | |
for i in itertools.count(1): | |
fizz = i % 3 == 0 | |
buzz = i % 5 == 0 | |
if fizz and buzz: | |
yield 'fizz buzz' | |
elif fizz: | |
yield 'fizz' | |
elif buzz: | |
yield 'buzz' | |
else: | |
yield i | |
if __name__ == '__main__': | |
print( | |
list( | |
itertools.islice(fizzbuzz(), 20) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment