Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students also viewed these Databases questions

Question

Define text analytics.

Answered: 1 week ago

Question

=+ a. a family deciding whether to buy a new car

Answered: 1 week ago

Question

=+10. How are inflation and unemployment related in the short run?

Answered: 1 week ago