Question: You are tasked with creating a number guessing game in Python. The program should be named guess.py . In this game, the computer generates a

You are tasked with creating a number guessing game in Python. The program should
be named guess.py.
In this game, the computer generates a random number between 1 and 100
(inclusive), and the player needs to guess the number within a limited number of
attempts based on their chosen difficulty level: easy (20 attempts), medium (10
attempts), or difficult (5 attempts).
The game provides feedback to the player after each guess, indicating whether
the guess is too high, too low, or correct.
Your task is to write a Python program that implements this game. Follow these
guidelines:
o Create a function generate_random_number() that generates a random
number between 1 and 100 and returns it.
o Create a function play_game(max_attempts) that implements the game
loop using while 1:
o Inside the loop, ask the player for their guess, compare it to the random
number, and provide feedback.
o If the guess is correct, break out of the loop.
o If the player exceeds the specified number of attempts for their chosen
difficulty level, break the loop and inform the player that they have failed.
o Display a message to the player when they guess the correct number,
along with the number of attempts it took.
o Use conditionals to check whether the guess is too high or too low and
provide appropriate feedback.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!