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 2.
like the programming challenge 1, this may be attempted individually or in pairs. This will likely take longer than a single session.
Programming Challenge 2 - Multiplication Test
Teachers would like a program that will help children learn their multiplication tables. The program needs to:
The program will ask 20 questions.
The questions will be a mixture of multiplication tables.
The program will check the answers and give feedback after each question.
The user will receive a score out of 20 when they have finished.
When designing your program you may have other ideas you may wish to include but these are the minimum requirements.
Let's look at these requirements:
The program will ask 20 questions. Use the same for loop from the question generator.
The questions will be a mixture of multiplication tables. Use the randint() function to generate numbers between 1 and 12.
The program will check the answers and give feedback after each question. Use if statements to check the answers, remember to use == to check for equality.
The user will receive a score out of 20 when they have finished. Use a variable to store the users score - make sure that this is outside of the for loop.
Some examples to help:
#for loop for i in range(1,21): #print the question number print("Question", i) #generate random numbers num1 = randint(1,12) #cast to int answer = int(user_input) #check answer if answer == (num1 * num2): #update users score user_score = user_score + 1
A complete version* of this program is available in the code example section as 6_multiplication_test.py
* There is often several ways of solving a problem, the version in the file should not be seen as the 'correct' solution.