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

## LO: Programming Challenge 1 - Examples.

To help us complete the program for challenge 1 we'll look at some example code that may solve some of the problems involved.

## Programming Challenge 1 - Question generator.

Teachers would like a program that will generate addition questions for them so they can include them in a test. The program needs to:

• Generate 20 addition questions using 2 and 3 digit numbers.

• Print out these questions including the question number (1 - 20).

• Print out the answers under each question so the teachers don't have to work them out.

Writing instructions:

```
#instructions
print("")
print("Welcome to the addition question generator!")
print("This program will generate 20 questions to test children")
print("and provide you with the answers so you don't have to")
print("")

```

A loop that will run twenty times:

```
#for loop
for i in range(1,21):

```

Generate random numbers. This will need to be included inside of the for loop so that a different number will be generated each time.

```
from random import randint

#generate a random number between 10 and 999
num1 = randint(10, 999)
num2 = randint(10, 999)

```

Print out the questions.

```
print(i, num1, "+", num2, "=")

```
• i is the variable used in the for loop for counting through the sequence of numbers generated by the range function (1, 2, 3 ... 20)

• num1 is the first random number between 10 and 999

• + character to go between the two numbers - remember that spacs will automatically be added by the print function.

• num2 is the second random number between 10 and 999

• = character to complete the number sentence.