I am having to set some extra work at home for my ten year old son. I found information on a game Fizz-Buzz and introduced it to my son, only to find that he had already played a variant at school.
Oh well.
By that time I had already created a python program to check his answers (written in simplistic style as I intend one day to get all of my kids to learn Python).
'''
Fizz-Buzz.py
Fizz-Buzz Game.
Instructions for two players, 3-5 game. (Easiest).
1. Players take it in turns counting from one to ninety-nine.
(Don't take too much or too little time between numbers
- try for a steady pace)
2. Player must say Fizz-Buzz instead of their number if the number is a
multiple of three and of five.
3. Otherwise, player must say Fizz instead of their number if the number
is a multiple of three.
4. Otherwise, player must say Buzz instead of their number if the number
is a multiple of Five.
Digit version
Use basic instructions 1-4 as above, then add the following rules:
5. Otherwise, player must say Fizz for each digit in the number that is
a three,
And player must also say Buzz for each digit in the number that is a
five.
(for example, say Fizz-one instead of 31, Fizz-two instead of thirty
two)
6. Remember, the rules must be applied in order so thirty three is
actually Fizz and not Fizz-Fizz as it is first a multiple of three
'''
fizz = 3
buzz = 5
digits_version = True
for tens in (0,1,2,3,4,5,6,7,8,9):
for units in (0,1,2,3,4,5,6,7,8,9):
number = tens*10 + units
if number == 0:
pass
else:
print "For", number, "Say",
if (number % fizz) == 0 and (number % buzz) == 0:
print "FizzBuzz"
elif (number % fizz) == 0:
print "Fizz"
elif (number % buzz) == 0:
print "Buzz"
elif digits_version:
saytens = tens
sayunits = units
digits_as_fizzbuzz = False
if tens == fizz:
saytens = "Fizz"
digits_as_fizzbuzz = True
if units == fizz:
sayunits = "Fizz"
digits_as_fizzbuzz = True
if tens == buzz:
saytens = "Buzz"
digits_as_fizzbuzz = True
if units == buzz:
sayunits = "Buzz"
digits_as_fizzbuzz = True
if digits_as_fizzbuzz:
print saytens,sayunits
else:
print number
else:
print number