Advertisement
nher1625

FizzBuzz

Mar 25th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. __author__ = 'Work'
  2.  
  3. from itertools import cycle, izip, count, islice
  4.  
  5. fizzes = cycle( [""] * 2 + ["Fizz"] )
  6. '''
  7. itertools.cycle( iterable )
  8. Make an iterator returning elements from the iterable and saving a copy of each.
  9. When the iterable is exhausted, return elements from the saved copy. Repeats indefinitely.
  10. Equivalent to:
  11.    def cycle(iterable):
  12.        # cycle('ABCD') --> A B C D A B C D ...
  13.        saved = []
  14.        for element in iterable:
  15.            yield element
  16.            saved.append(element)
  17.        while saved:
  18.            for element in saved:
  19.                yield element
  20. '''
  21.  
  22. count = 1
  23. while count < 100:
  24.     if count % 3 == 0 and count % 5 == 0:
  25.         #if count % 5 == 0:
  26.         #    print("FizzBuzz")
  27.         #else:
  28.             #print("Fizz")
  29.         print("FizzBuzz")
  30.     elif count % 3 == 0:
  31.         print("Fizz")
  32.     elif count % 5 == 0:
  33.         print("Buzz")
  34.     else:
  35.         print(count)
  36.     count += 1
  37.  
  38. for i in range(1, 101): print( "Fizz"*( i % 3 == 0 ) + "Buzz"*( i % 5 == 0 ) or i )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement