python
FizzBuzz
FizzBuzz is a famous little puzzle. Count from 1 upwards, but:
- if the number can be divided by 3, say
Fizz - if it can be divided by 5, say
Buzz - if it can be divided by both 3 and 5, say
FizzBuzz - otherwise, just say the number
So: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, ...
"Can be divided by 3" means the remainder is 0: n % 3 == 0.
Your mission
- Write
fizzbuzz(n)that returns the right word for the numbern(as a string, sofizzbuzz(7)returns"7"). - Use a loop to print the answers from 1 to 30.
Watch out for the order of your
ifs: what happens to 15?