Created
May 14, 2014 17:19
-
-
Save benjaminEwhite/7028b3227f0886c308f5 to your computer and use it in GitHub Desktop.
fizzbuzz with functions demo solution
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 sys | |
def _is_divisible(a, b): | |
""" Is a evenly divisible by b ? """ | |
return a % b == 0 | |
def fizz_buzz(limit=100): | |
""" Do fizz buzz up to limit number """ | |
for val in range(1, limit+1): | |
if _is_divisible(val, 15): | |
print "fizz-buzz" | |
elif _is_divisible(val, 5): | |
print "buzz" | |
elif _is_divisible(val, 3): | |
print "fizz" | |
else: | |
print val | |
if __name__ == '__main__': | |
limit = int(sys.argv[1]) | |
fizz_buzz(limit) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment