Skip to content

Instantly share code, notes, and snippets.

@amberj
Created April 5, 2012 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amberj/2314714 to your computer and use it in GitHub Desktop.
Save amberj/2314714 to your computer and use it in GitHub Desktop.
FizzBuzz
# fizzbuzz.py
# Python implementation of FizzBuzz (http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/)
#
# Author: Amber Jain (http://amberj.devio.us/)
# Problem description:
# Write a program that prints the numbers from 1 to 100.
# But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz".
# For numbers which are multiples of both three and five print "FizzBuzz".
# Problem source: http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/
def fizzbuzz(n):
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
print 'FizzBuzz'
elif i % 3 == 0:
print 'Fizz'
elif i % 5 == 0:
print 'Buzz'
else:
print i
fizzbuzz(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment