For Project 3, we'll be creating a guessing game in Python.
You'll continue to learn more concepts in Python as well as reinforce some of the software development steps from the previous project.
By the end of this project, you will have gained valuable experience and foundational skills that will be useful for future projects:
Create and use while loops in Python
Create and use for loops in Python
Combine conditional statements with loops
Learn about loop control statements
Learn how to validate user input
These skills are essential for anyone starting in programming and will help you tackle more complex projects in the future.
Listen to Ashton below, he has a program he wants you to build. If you're still not sure afterwards, you can chat with him using the chatbot below.
📖 Afterwards, write down three requirements into your workbook, in plain-English, that you think Ashton wants you to include in the program.
An example of this might be: "The program should greet the user and explain that it is a Guessing Game".
📖 In your workbook create an IPO Diagram for the game
An IPO diagram stands for Input-Process-Output, and it's a simple way to outline what a program needs to do. It helps you identify what information goes into the program, what steps the program will take to process that information, and what you expect to come out as a result, making it easier to plan and write your code.
This time you will need to write a general description of the process. This can just be a plain-English explanation of how the game works.
If you go more detailed and algorithmic here, we begin to get into the next phase, design - and that is ok too.
Design is your game plan. Before you start coding, you sketch out what steps your program needs to take and how it should flow.
📖 In your workbook, complete the screen design and pseudocode activities.
Pseudocode:
Pseudocode is a method of describing the logic in an algorithm. It makes use of capitalised keywords and indentation to show control structures used. In pseudocode:
keywords are written in capitals
structural elements come in pairs
E.g. for every BEGIN there is an END, for every IF there is an ENDIF
indenting is used to identify control structures in the algorithm
Examples:
BEGIN
INPUT length as "Enter length of rectangle: "
INPUT width as "Enter width of rectangle: "
SET area to length x width
DISPLAY "Area of rectangle: " + area
END
BEGIN
INPUT age as "Enter your age: "
IF age >= 18 THEN
DISPLAY "You are eligible to vote."
ELSE
DISPLAY "You are not eligible to vote."
END IF
END
BEGIN
// Welcome to my loop
counter = 0
WHILE counter < 5
DISPLAY "This is loop number " + counter
counter = counter + 1
END WHILE
END
Now comes the fun part: actually making your program. This is where you write the code. Link to Project 3.
There are four labs to complete in order to learn the concepts necessary to complete this project. Complete these first.
Learn how to create and use a while loop in Python
Get set up on GitHub with Project 3
Learn how to create and use a for loop in Python
Learn how to check user input and ensure it is valid
Learn how to generate random numbers in Python
Once again I have some further requirements for you to follow.
I have broken these down into two categories:
less comfortable - just the basics
more comfortable - for those of you after more challenge
Less Comfortable:
Generate a random number between 1 and 100
Use a loop to keep guessing until correct
Use input validation to ensure the number is within range
More Comfortable
Extend input validation to ensure that it is also a valid number
Keep track of the number of guesses and include this in the final message
Allow the user to configure the range before the game starts
Prompt the user to play again or exit at the end
Keep track of the best score if doing multiple rounds
Testing this time will be a little trickier due to the random nature of the program.
You will need to either run the program a number of times or comment out the random value and use your own for testing.
📖 Either way, in your workbook, complete the testing table and come up with a way to test the boundaries, pathways and for faulty inputs.
Go back through your program and ensure it is maintainable by using code commenting and meaningful variable names.