Skip to content

Instantly share code, notes, and snippets.

@josephkern
Created November 16, 2012 15:12
Show Gist options
  • Save josephkern/4088059 to your computer and use it in GitHub Desktop.
Save josephkern/4088059 to your computer and use it in GitHub Desktop.
Python FizzBuzz
import sys
def is_3(n):
if not n % 3:
return True
def is_5(n):
if not n % 5:
return True
for n in range(1,101):
if not is_3(n) and not is_5(n):
sys.stdout.write(str(n))
else:
if is_3(n):
sys.stdout.write("Fizz")
if is_5(n):
sys.stdout.write("Buzz")
sys.stdout.write("\n")
#Another method
def is_3(n):
if not n % 3:
return True
def is_5(n):
if not n % 5:
return True
for n in range(1,101):
if not is_3(n) and not is_5(n):
print str(n),
else:
if is_3(n):
print "Fizz",
if is_5(n):
print "Buzz",
print #but ... yuck
@josephkern
Copy link
Author

An nice implementation here as well https://gist.github.com/4088324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment