Computers and Technology
Computers and Technology, 06.12.2019 22:31, bob7220

Modify the guessing-game program so that the user thinks of a number that the computer must guess.

the computer must make no more than the minimum number of guesses, and it must prevent the user from cheating by entering misleading hints.

use i'm out of guesses, and you cheated and hooray, i've got it in x tries as your final output.

(hint: use the math. log function to compute the minimum number of guesses needed after the lower and upper bounds are entered.)

and here is the code i wrote that works until one point:

# modify the code below:
import random
import math

smaller = int(input("enter the smaller number: "))
larger = int(input("enter the larger number: "))

count = 0

print()
while true:
count += 1
mynumber = (smaller + larger) // 2
print('%d %d' % (smaller, larger))
print('your number is %d' % mynumber)
choice = input('enter =, < , or > : ')
if choice == '=':
print("hooray, i've got it in %d tries" % count)
break
elif smaller == larger:
print("i'm out of guesses, and you cheated")
elif choice == '< ':
larger = mynumber - 1
else:
smaller = mynumber + 1

this guessing game works up until this question:

failed: test 0-50, when 1 is picked then switched when correctly guessed.

this is the input the automater did:

enter the smaller number: enter the larger number:
0 50
your number is 25
enter =, < , or > : 0 24
your number is 12
enter =, < , or > : 0 11
your number is 5
enter =, < , or > : 0 4
your number is 2
enter =, < , or > : 0 1
your number is 0
enter =, < , or > : 1 1
your number is 1
enter =, < , or > : i'm out of guesses, and you cheated
1 1
your number is 1
enter =, < , or > :
traceback (most recent call last):
file "guess. py", line 16, in
choice = input('enter =, < , or > : ')
eoferror: eof when reading a line

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:30, lizz1228
Kto rozmawia z clamentain przez krótkofalówke w the walking dead w 4 epizodzie
Answers: 1
image
Computers and Technology, 24.06.2019 15:30, hemolelekeakua
How do i change the size of my bookmarks in my bookmarks bar in google chrome? ? plz hlp me
Answers: 2
image
Computers and Technology, 25.06.2019 08:00, alizeleach0123
A( the heart of an information system, is a collection of all relevant facts organized in a series of integrated files.
Answers: 1
image
Computers and Technology, 25.06.2019 09:30, jhahn001
Which of the following is a reason to include the people who will be using the new technology in conversations about technology upgrades for a business? a. the users would likely know if an upgrade would be necessary or even useful. b. the users would know more about the software than people in the it department. c. the users will be paying for the upgrades with their own money. d. the users will assume the upgrade will cause a drop in productivity.
Answers: 1
Do you know the correct answer?
Modify the guessing-game program so that the user thinks of a number that the computer must guess.

Questions in other subjects:

Konu
English, 25.03.2021 16:50