Skip to content

Instantly share code, notes, and snippets.

@bcambel
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save bcambel/78bd12676214779fc7ed to your computer and use it in GitHub Desktop.

Select an option

Save bcambel/78bd12676214779fc7ed to your computer and use it in GitHub Desktop.
FizzBuzz
def can(n,m): return n%m==0
for i in range(1,100):
if can(i,3) and can(i,5):
print "FizzBuzz",i
elif can(i,3):
print "Fizz",i
elif can(i,5):
print "Buzz",i
#Version 2 without MODulo operation
#precalculate
threes=range(3,100,3)
fives=range(5,100,5)
fifteen=range(15,100,15)
for i in range(1,100):
if i in fifteen:
print "FizzBuzz",i
elif i in threes:
print "Fizz", i
elif i in fives:
print "Buzz", i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment