Advertisement
tepples

Configurable fizzbuzz in Python

Nov 23rd, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """
  3. configurable fizzbuzz in Python 2.6+ and Python 3
  4. 2014 Damian Yerrick, Creative Commons Zero
  5. """
  6. from __future__ import print_function, division
  7. import sys
  8.  
  9. divs = [
  10.     (3, "fizz"),
  11.     (5, "buzz"),
  12. ]
  13. for n in range(1, 101):
  14.     need_num = True
  15.     for (divisor, symbol) in divs:
  16.         if n % divisor == 0:
  17.             print(symbol, end='')
  18.             need_num = False
  19.     if need_num:
  20.         print("%d" % n, end='')
  21.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement