Instantly share code, notes, and snippets.

# trustrachel/fizzbuzz.py Created Oct 9, 2013

 # 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: # http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html # 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: http://docs.python.org/2/library/functions.html#range # % 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" else: print n