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

LO: Programming Challenge 1.

It is now time to use everything we have learned and put it together to create programs to solve problems like real programmers. These challenges will take longer than a single session and can be attempted individually or by working in pairs - remember, all ideas can be tried out using the IDLE shell and it's a good idea to use flow charts to help organise and understand what is happening in your program.

Before we begin it might be a good idea to look back at our suggestions for good programs:

Remember you can also use the 6_game_loop_template.py available below - but don't use it for planning your program, that's what the flow charts are for.



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:

When designing your program you may have other ideas you may wish to include but these are the minimum requirements.



As this is the first challenge we will look into these requirements more closely and discuss how they could be achieved*:


Generate 20 addition questions using 2 and 3 digit numbers. This looks like we will need to use the randint() function to generate the 2 and 3 digit numbers and we will need to use a for loop to do this 20 times. This can be tested in the shell in IDLE.

Print out these questions including the question number (1 - 20). The question numbers could be the same number as the number of loops e.g. first loop = first question number, second loop = second question number...

Print out the answers under each question so the teachers don't have to work them out. This looks like we would need another variable to reference the total of the two numbers...



Remember!!!! Do not try to write this program in one go! Make or draw some flowcharts to help organise your thinking. Test each idea in IDLE shell or write a small function and test it by writing a small file and running it.

Examples and demonstrations will be explored in 6.3b.









* A complete version** of this program is available in the code example section as 6_question_generator.py

** There is often several ways of solving a problem, the version in the file should not be seen as the 'correct' solution.


Code Examples

Resources