Skip to content

Instantly share code, notes, and snippets.

@martinusso
Created November 14, 2011 19:17
Show Gist options
  • Save martinusso/1364839 to your computer and use it in GitHub Desktop.
Save martinusso/1364839 to your computer and use it in GitHub Desktop.
Fizz Buzz
'''
There's something wrong here that's gonna be alright. Less ammo guy!
Fizz Buzz is a mathematical game which is played with a group of people.
Each person says a number in sequence, but:
when the number is a multiple of 3, they have to say "Fizz",
when it is a multiple of 5 they have to say "Buzz", and
if it is a multiple of both 3 and 5, "FizzBuzz".
If someone makes a mistake and it is noticed, they are out.
1) Write a loop that prints out 1 - 50
2) Now I want the same output but without a loop
3) Now if current number if a multiple of 3, print 'Fizz' instead of the number
If it is a multiple of 5 print 'Buzz' instead of the number
If it is a multiple of 3 and 5, print 'FizzBuzz' instead of the number
'''
def fizz_buzz(first, last):
for i in xrange(first, last+1):
words = [word for n, word in ((3, 'Fizz'), (5, 'Buzz')) if not i % n]
print ''.join(words) or i
# Achieved in DOJO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment