Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve in python without using break to stop the loop. 2) Write a peogram that generates a random number berween NIM and NAX. Wes

Please solve in python without using "break" to stop the loop. image text in transcribed
image text in transcribed
image text in transcribed
2) Write a peogram that generates a random number berween NIM and NAX. Wes contants NIB = 1 and MAX =100. To generate a random number, youd seed to import the random module Thas is done with the following statement import random at the top of your program. Then, to generate a randon number, use the randint function. number = random. Fandint (MIN, MaX) 1 At this point, your program should gencrate a number between 1 and 100. Run is a few times to coevinee yourself it is geterating random numbers. b) Now, allow the user to enter a single guess. Issue an appeopriate message. At this point, we still display the computer : random number so ue know if the messages are correct (etentually we talle this out). A fow trial runs: Enter a guess: 50 Too high 13 Enter a quess: 50 . Too low 73 Water a quea: a 50 Juet right 50 c) Now pat a koop in to continae to ask for gusses until the user gets it righit, gring the user a too highh/too low mesuge each time they mise. Hereb a trial run: Enter a quess : 50 Too high Finter a guene: 25 Toe low Fncet a quess: 35 7oo high Fater a quess: 30 Too low Encer a quesis: 32 7 oo hiqh Kater a ques:: 31 31 d) Nest add a coxanter to let the user kricru how mant guesses it took. Enter a questit so Too high Enter a guens: 25 Too bigh Inter a guess: 15 Too low Lntor a guesst 20 20 It took 4 trien c) Declare a cunalana NDX TRIES = 5. Adil a peifultion mo your hop, so your perograns terminates if the user has gucssed MhX_ T.1kes cimes. Take a book at the tuo tral runs beksa: Note that in the sceond rua the program terminases even ahexade the number waset fuessed. Ences a guesit 50 Too ton Enter a quesmi 75 75 It took 2 teses thter a quessi 50 Too higth Enter a quensi 25 Too low Envef a guenst: 35 Too I In Bnter a tuenst 40 Too low Enter a quens: 45 Too low 4B The progeram termunates becauce the ueer has run out of enies. 1) Adul a cond leional afice yout loof to let the user knone way the progeath terminutnd (cieher they yuessed ir or they ran out of tries)]. Enter a quess: 50 Too low Enter a gueast 75 Fog RLgh tnter a guess: 60 Too hiqh Enter a quensi 55 Too 1dw Enter a guessf 56 Forty, you" re but of Eries, The number was 57 10) Sulil have time leit? Allow the unet to play mulciple roends. 1 at chinking of a nunber between 1 and 100 You have 5 tries to quess it. Cood luek! Enter a quesa between 1 and 100150 Too hiph Enter a quesm between 1 and 100125 Topo lon Enter a gueas betwees I and 100 : 30 Too low Enter a queat between 1 and 100+40 Too high Enter a guesa between i and 100: 35 Sorry, you are out of trits! Fhe nucber wat 36 Pray again? (x or N) y I an thinking of a number between 1 and 100 You have s tries to quess it. Cood luck! Enter a guena between 1 and 100150 Too low Enter a queas between 1 and 100: 75 Too lew Enter a gueus between 1 and 10018.5 Too low Enter a guess between 1 and 100190 Foo Ion Enter a gueut between 1 and 100;95 Sorry, yos are out of trieat Thin nunber was 100 Play again? (Y or W N ) b) Still time Ieft? Validare each gucki, ensuring it's between MIN and MXX. Notice in the ampic tun that invald gaeses duet count against their MAX_.. FRTES limit: I an thinking of a number between 1 and 100 You have 5 triea to quean it. Cood luck! Enter a gueas between 1 and 100: 50 Too low Enter a quebt between 1 and 100110 tnvalid ingut Enter a guest between 1 and 100 ; 75 Too high Enter a quess between-1 and 100;65 Too bigh Enter a guens between 1 and 100 : 10 Invalid input Enter a guess between 1 and 100:60 Too high Enter:a gues between 1 and 1001. 55 Sorzy, you are out of teleal The number wat 59 play agadn? [Y of N) n

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

Data Visualization A Practical Introduction

Authors: Kieran Healy

1st Edition

0691181624, 978-0691181622

More Books

Students also viewed these Databases questions