04_HL_Planning_ans_2017

Higher Lower Planning – No Frills Version
Credit: This answer is based on original planning and code developed by Lydia Hopkins and is
used with her permission.
Main Routine
1.
2.
3.
4.
5.
Ask the user to choose a number between 1 and 100.
Generate a random number between low and high (secret)
Set num_guesses to zero
Ask user to guess the number (guess). Check that ‘guess’ is an integer between low and high
Check to see if they got it right…
a. If guess = answer, print ‘well done’, display num_guesses and end round
b. If guess > answer, print ‘lower and add one to num_guesses
c. If guess < answer, print ‘higher’ and add one to num_guesses
6. Repeat steps 4 - 6 until guesses = answer
7. Ask the user if they want to keep_going (press <enter> to play again or any key to quit)
8. If keep_going is <enter>, repeat steps 1 – 7, otherwise end the program
Functions
Numcheck (takes in type, question, low and high)
1. Set valid to False
2. While valid is false…
3. Ask the user the question
a. If the response is a number of the correct type (ie: float / int) between the
low and high specified when the function was called, return the response to
the main routine
b. If the response was not valid, repeat the question.
Input / Output etc
process
output
Name
secret
num_guesses
Data Type / Scope
integer / global
integer / global
input
guess
integer / global
process
keep_going
string / global
Process
valid
Boolean / local
Process
Response
Float / int / local
Description
Controls what the secret number is
Stores how many number of
guesses the user makes
Stores the guess made by the user,
which is an integer that is more than
(or equal to) 1 and less than (or
equal to) 100
controls whether the program loops
(enter to loop, any key to quit)
Controls whether the number
checking function returns a valid
response to the main routine
Validated number that is returned
to the main routine by number
checking function
Development Process
I developed my code in a series of steps which have been summarised in the code.
Here is the final version list showing the iterative process…
I tested the program at each stage to ensure that the components worked correctly.
Below is evidence of my final testing showing that the game is robust.
GTT: The above is partial evidence for developing a program in a series of steps. It
should have included mention of when functions were implemented (possibly
between v1 and v2 above).
If your program is more sophisticated, there would be more steps / versions
showing a systematic approach to implementing the various features.
Test Plan
<Actual column can only be filled in once program has been created / tested. This might remain
blank if the material is submitted before the program has been written>
GTT: Below is a suggestion on how one could do the first (and second parts) of a test plan
where we might not know exactly what question / situation will be generated by the
computer. You’ll notice that we have a description for the test data instead of concrete
numbers. There are other valid ways of doing this but the material below should be
useful. Note that this game cannot be lost – if your game is ‘losable’ you should supply
testing / evidence showing that it is possible to lose.
Purpose: Check that the program generates a random number for the ‘secret’ number
Test Data
Run the program a few times and
print the secret number to the
screen.
Expected
The secret number should always
be an integer between 0 and 100
For the first number, choose a guess
that is lower than the number, then
choose a guess that is higher than
the number and finally guess the
correct number.
Round 1, Game 1
Too low
Too high
Congratulations
For rounds 2 and 3, guess the
correct number in one try
Round 2, Game 1: Congratulations
Round 3, Game 1: Congratulations
<loops>
Then loop the program and guess
the correct number in one try for all
three rounds of the new games
Check that the game ends
Round 1, Game 2: Congratulations
Round 2, Game 2: Congratulations
Round 3, Game 2: Congratulations
<ends>
Actual
See below