Question: How do you write this in Python? In pa5_game.py, implement a guessing game given by the following specifications. The player's goal is to guess a

How do you write this in Python?

How do you write this in Python? In pa5_game.py, implement a guessing

In pa5_game.py, implement a guessing game given by the following specifications. The player's goal is to guess a random number that has been generated (don't worry about writing code for this - it has been provided later in this document). They are given a limited number of attempts to try and guess the number correctly. We allow the player a maximum of 8 guesses. T Once the player starts guessing, for each incorrect guess, the player is informed whether they must "Guess higher" or "Guess lower the next time. The game ends either when the player guesses the correct number, or when they run out of attempts. If the player won, display "You won!", and if they lost, display "You lost!". If they lost, also print what the original number was. The following code generates a random number between 1-100: import random random_number = random.randint(1,100) Copy these lines as-is into pa5_game.py, and implement the rest of the game. HINT: Use a while loop or a for loop for implementing the game's main logic, i.e. reading the player's guesses, checking if each guess is correct/incorrect, and displaying the appropriate messages at each step. Example: >_user@sahara:- [user@sahara - ] $ python -i game.py Enter a guess: 45 Guess Lower! Enter a guess: 30 Guess higher! Enter a guess: 40 Guess higher! Enter a guess: 42 Guess lower! Enter a guess: 41 You win! >>>

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 Databases Questions!