Name: Mr Farmer

Exam Number: 1234


Double Or Quit

Planning

Analysis - There is a detailed analysis of what is required for these tasks justifying their approach to the solution

For this task I will start by importing the random module. I need to do this as I will need to generate a random number later in the program to use for luck (75% chance of doubling). Once I have done this, I will use the print function to output the instructions for the game. I will then declare a variable called score and set it’s value to 1. This variable will be used to store the players score throughout the game. Next I will use an input to ask the user if they want to play and I will store the result in a variable called play. Now I will use a while loop for the main program when the user chooses to play. If they choose not to play then they will get an output message using the print function telling them their score, which will be one. Inside the while loop I am going to declare a variable called luck and then use the randint function to generate a random number between 0 and 3. I will then use an if statement to test the luck variable and output the correct message. If luck is equal to or greater than 1 then score will be doubled, the user will be told their new score using the print function and then they will be asked if they want to continue playing. If they choose yes then the program continues to follow the while loop until the user gets a 0 or they choose to stop playing. If the user get’s a 0 then score is set to 0, they are told they have lost and given their score which is 0. Play is set to No so the program can come out of the while loop.

Flowchart –Make sure you use the correct shapes. If you need more room, then use connectors

Pseudocode - Use http://my.dynamic-learning.co.uk to help you

IMPORT random

PRINT instructions

SET score to 1

INPUT - ask them if they want to play

WHILE play == 'y':

GENERATE Luck using randinT

IF luck >= 1:

DOUBLE score

PRINT new score

INPUT - ask them if they want to continue

ELSE

SET score to 0

PRINT losing message and score

SET play to n

PRINT final score

Success Criteria – This is what you will test against later

·  Game starts with a score of 1

·  User is able to choose if they want to play

·  If they choose to play then a random number between 0 and 3 is generated and stored

·  If the stored number is 1, 2 or 3 then the score is doubled

·  The user is able to continue to playing to can choose to keep their score

·  If user chooses to continue then a new random number is generated and the above is repeated

·  If user chooses not to continue then their final score is printed

·  If the stored number is 0 then the user loses and program ends and their final score is printed

Variables, Structures and Validation

Variable / Structure / Validation
Score / Integer / Initially set to 1
Play / String / Y or N
luck / integer / Random number between 0,3

Development

Development and Systematic Testing

This shows my instructions are being printed correctly

This shows score has been set to 1

This shows the input is working as the user is able to choose if they want to play

This shows the while lip is working and that a random number for luck is being generated. The while loop is infinite at the moment.

This should that the if statement is working and if luck is => 1 then luck is doubled and printed and the player is asked to play again

This shows the else is working for when luck is 0 and the user is told they lost and scored 0

This shows that if the user chooses not to play then they are told their final score which is 1

This shows that the final score is output when luck is 0

This shows that the final score is output after the user has doubled their score and then chooses not to play anymore.

Final Program – with comments

This shows my final program where each section has been commented.

Testing

Test Plan (you can add more rows if you want) – You need to use the success criteria form the planning here.

Test Data / Expected
Game starts with a score of 1 / Score = 1
User is able to choose if they want to play / User is asked if they want to play
If they choose to play then a random number between 0 and 3 is generated and stored / Luck = random number between 0 and 3
If the stored number is 1, 2 or 3 then the score is doubled / Score is doubled and printed
The user is able to continue to playing to can choose to keep their score / User can choose to continue
If user chooses to continue then a new random number is generated and the above is repeated / Score is either double or user loses
If user chooses not to continue then their final score is printed / Final score is printed (=> 2)
If the stored number is 0 then the user loses and program ends and their final score is printed / Losing message printed and final score printed

Testing Evidence – Print screens showing each of the tests in your test plan

Evaluation

My program is successful as it meets each of the success criteria set out in the planning stage. My program stars by telling the user about the game and their chances of winning or losing. It Allows them to choose if they want to play or not and then generates a random number between 0,3. 0 is used for the 25% chance they will lose and 1,3 is used for the 75% chance they will win. The program tells them what is happening at each stage and then prints out their final score at the end.

During this program I found using the techniques learnt in lesson fun and challenging. I had to use a while loop with an if/else statement inside. It was challenging figuring out how to use the indents properly.

To improve I would do 2 things. I have would have a limit score for winning and I would add a counter so the user only had a certain amount of goes.

St James School

54245