Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer in Python please! Assignment Write a program that allows the user to play a guessing game. The game will choose a secret number, a

Answer in Python please!

image text in transcribed

image text in transcribed

Assignment Write a program that allows the user to play a guessing game. The game will choose a "secret number," a positive integer less than 1000 . (For testing purposes, it must also be possible to specify the number; how' to do that is explained below.) The user has 10 tries to guess the number. Your program should be defined with a main (s function and a call to that function at the bottom of your program file. It should be defined as follows: def main ( initislanswer = None ): * Loop to play any nunber of qames. Before each, ask * the player if she wsnts to continue. * A If ' N ', priat a Coodbye nesgage and retura * * If ' Y ', choose an angwer and play the game, which * involves looping to aceept up to 10 answers. * * otherwise, print. an error message and try again. m * If you (or the TT ) want to test your program with a specific answer * you can supply that as a paraneter to main. Por examplet this would run your F program with a randomly chosen answar: man() * whereas, main(500) ; would run yaur program with a specific answer of 500. main(1) Your program should hegin by printing a welcome message (see examples below). Then ask the player if she is ready to play. The answer should be ' Y ' or ' N '. If the answer is ' Y ' play a game and ask again. If ' N ', print a gondhye message und exit. If anything elsc, print an error messuge and ask agrain. When you call main(), you can either specify an answer to use or not. If you do specify an unswer, that answer will be used in all games. If not, you'll choose a different random answer in each game. Here's how to do that. In your code, when the player has specified ' Y ', meaning she d like to continue, you must decide what the answer for this game is. You can do that with the following cade (within main0): \# vaer has just specified ' Y ' If initlalknswer: \& meenings initialangwer isn't Hone thisCamesmer = initialarswer else: thisdamelunewer - random.randint( 1, 999) In each game, accept up to 10 guesses from the user, one at a time. If a guess is correct, congratuate the user and end the game. If the user makes 10 tries without success, say so and end the game. Short of 10 tries, if the guess is too low, say so and continue. If too high, say so and continue. See the examples belows. You can assume that the user will enter an integer as a guess; however, your program must verify that each guess is positive and less than 1000. If it is not, it should print an error message and reprompt the user. Don't coint illegal guesses against the user's allowed guesses. addition to multiple games within several of the calls. > pythan GuessingCame.py Welcame to the guessing game! Cood luck! Lre you ready to play (Y/k):Y See if you can guess the 'secret number'! Enter an integer fron 1 to 999:100000 That.s an illsgal guess. Try again! You have 10 gunsses laft.. Enter an integer fron 1 to 999:3 That a an 11leqal queas. Try aqain! You have 10 queases left. Enter an 1nteger from 1 to 999;500 Congratulations, yau gat it! You took 1 guesses! Are you ready to play (y/k)=Y See if you can guess the 'secret number'I Enter en liteger from 1 to 999: 500 Congratulations, Yau gat it! You took 1 guesses! Rue you ready to play (Y/k): z sorry, I didn't recognize your answer, Try againd Are You rendy to play (Y/N)=N Wel1, cone again later. Goodbye! > pythar cuessingcame.py te the number is still 500 Welcame to the gueseing game! Cood luck! Are you ready to play (Y/N)=Y See if you can guess the 'secret number'! Enter en integer fron 1 to 999: 100 Your guess is too low. Try again! You have 9 guesens left. Enter an integer fron 1 to 9991900 Your quesa 1 a too high. Try againl You have 6 quesses left. Enter an integer from 1 to 999;200 Your guess is too low. Try again! You have 7 guesses left

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

Students also viewed these Databases questions

Question

=+4. How might you improve on your weaknesses?

Answered: 1 week ago