Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to make this codes more effieciently? I want to make computer (python) to guess user number. import random goodbye='Goodbye ' while True: smaller =int(input('Enter

How to make this codes more effieciently? I want to make computer (python) to guess user number.

import random goodbye='Goodbye ' while True: smaller =int(input('Enter the smaller number: ')) larger =int(input('Enter the larger number: ')) userNumber =int(input('Enter the numberthat you want me to guess: ')) count =0 while True: count +=1 myNumber =random.randint(smaller,larger) if userNumber > myNumber: print(myNumber) print('Too small ') elif userNumber < myNumber: print(myNumber) print('Too large ') else: print('I got it right in',count,'tries! ') break answer=input('Would you retry this program? Press enter to exit or any key to continue: ') if answer== '': print(goodbye) break else: print()

As you can see, computer is generating new random number which is not that efficient. How can I write codes so that I can make python to guess my number more quickly?

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

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

4. Write goals down and regularly monitor progress.

Answered: 1 week ago