Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
# 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".
# This is a moldly oldie in the programmer community, it's known as "FizzBuzz" (for obvious
# reasons). Here's a blog post:
# This solution runs through every number between 1 and 100, checks if they are evenly
# divisible by five, three, or both five and three, and prints the appropriate thing.
# range function:
# % is the modulo operator. It divides the value of one expression by the value of another,
# and returns the remainder.
for n in range(1, 101):
if n % 5 == 0 and n % 3 == 0:
print "FizzBuzz"
elif n % 3 == 0:
print "Fizz"
elif n % 5 == 0:
print "Buzz"
print n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.