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.3b

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:



Writing instructions:


#instructions
print("___ADDITION QUESTION GENERATOR___")
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("think about it!")
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, "=")

			


Code Examples

Resources