Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benjaminEwhite/7028b3227f0886c308f5 to your computer and use it in GitHub Desktop.
Save benjaminEwhite/7028b3227f0886c308f5 to your computer and use it in GitHub Desktop.
fizzbuzz with functions demo solution
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