Level 2

icon picker
Challenge 2


Aim:

Expand your knowledge with a bigger project

Task 1: Number Guessing Game

Learning Objectives: PY02.1.4, PY04.2.1, PY02.6, PY05.2.1, PY08.2
In this task, we’re going to build a Number Guessing Game
Task
On Repl.it, create a new Repl called ‘L2 Challenge 2: Task 1’.
Code a guessing game where the user guesses a secret number.
After every guess, the program tells the user whether their number was too large or too small.
Keep a count of how many tries the user has attempted
At the end of the game, the number of tries needed should be printed.
It should only count as one try if they input the same number multiple times consecutively.
When the user answers the correct number the program should show a “You Won!” message
Hints
Break down the code into mini-tasks and plan your solution
To generate a random number you can use the
Remember that == checks for equality in value and type.
Beware the infinite loop! You can chain conditions together in Python or use the break clause to exit a loop.
You can read more about infinite loops and how to manage them
Make sure you are separating out different parts of the functionality into different functions.
This will make your code easier to debug, and also easier to read.

Task 2: Reflection

Learning Objectives: PY02.1.4, PY04.2.1, PY02.6, PY05.2.1, PY08.2
Task
Now that we’ve got our finished program take a look at your code
How many functions have you used?
How readable is your code?
How good are the variables names you've used?
e.g. x1 vs user_guess
If you were to come back to your code in three/six/twelve months, how easy would it be to understand?
With this in mind, your code to split it into a suitable amount of functions, ensure you’re using good variables names and - more generally - make it so it’s easy to understand for future you.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.