Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started