Skip to content

Instantly share code, notes, and snippets.

@jaysonrowe
Created January 11, 2012 03:05
Show Gist options
  • Save jaysonrowe/1592775 to your computer and use it in GitHub Desktop.
Save jaysonrowe/1592775 to your computer and use it in GitHub Desktop.
FizzBuzz Python Solution
def fizzbuzz(n):
if n % 3 == 0 and n % 5 == 0:
return 'FizzBuzz'
elif n % 3 == 0:
return 'Fizz'
elif n % 5 == 0:
return 'Buzz'
else:
return str(n)
print "\n".join(fizzbuzz(n) for n in xrange(1, 21))
Copy link

ghost commented Feb 5, 2022

1_R2fnmU0IU_YB5J2bz4_3hQ

@DaCuteRaccoon
Copy link

In 480 bits (60 bytes) or 60 chars:

for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)

@VanVictor
Copy link

def fizzBuzz(n):
# Write your code here
for i in range(1, n + 1):
if i % 5 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
elif i % 3 != 0 or i % 5 != 0:
print(str(i))

Proof, code at work

@connorjnel
Copy link

def fizzBuzz():
stack = range(1, 100, 1)
for item in stack:
if item % 3 == 0 and item % 5 == 0:
item = "FizzBuzz"
elif item % 3 == 0:
item = "Fizz"
elif item % 5 == 0:
item = "Buzz"

    print(item)

fizzBuzz()

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