design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts.

use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs

6.5b

LO: Programming Challenge 3.

This programming challenge is to recreate a game while solving division problems. Let's start with the game FizzBuzz: players take turns to count aloud, replacing every number that is divisable by 3 with the word "fizz" and any number divisable by 5 with the word "buzz". Numbers that are divisable by 3 and 5 are replaced by combining both words by saying "fizzbuzz". A game would look like this:

The goal of this challenge is to write a program that recreates this game up to 100.

As this is the last challenge we shall keep the advice to a minimum. To begin with, the program has to print out a list of numbers from 1 to 100:


for i in range(1,101):
    print(i)

			

How do you check if a number is divisable by another? If we recall 6.4a if a number is divisable by another then it will not have a remainder. Look at this example:




number = 3

if number % 3 == 0:


			

Evaluating two numbers in an if statement:


#check if a number is greater then 2 and divisable by 2

if number >2 and number % 2 == 0:


			

Making only one choice:


if number >10:
    print("bigger than 10")
elif number % 2 == 0:
    print("even")
else:
    print(number)


			

If the number is 20 then it will print out only 'bigger than 10' as that is the first statement that is True - it doesn't matter that 20 is also even.

As with the other challenges, this can be attempted in pairs or individually and will take longer than one session. There are several different ways to complete this challenge so children should not be put off if their code does not look like others.




In the code example section you will find three possible solutions to this challenge. These programs are not commented to allow you to work out what is going on in each one.


Code Examples

Resources