Created
November 16, 2012 15:12
-
-
Save josephkern/4088059 to your computer and use it in GitHub Desktop.
Python FizzBuzz
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_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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An nice implementation here as well https://gist.github.com/4088324