subject

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

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:30
This first part of the film shows the early history of motion pictures. how accurate do you think the portrayal of the early motion picture industry is? why? is historical accuracy important in films and theatre productions? explain. in the scene where don is going to the party (starting at time code 14: 51), we see a street scene as he first rides with cosmo and then with kathy. what aspects did the filmmaker include to make the scene look and feel like don, cosmo, and kathy are riding in a car on a street? think about elements such as scenery, sound, props, lighting, and so on. a "talkie" picture is shown starting around time code 21: 15. how does the audience in the film react to the "talkie"? what influence do audiences have on film and theatre performances? how do film and theatre actors influence audiences? in the musical scene with cosmo (starting at time code 27: 00), how does the actor use props? what is the result? do you think the use of props effectively fulfilled the artistic vision for this musical number? why or why not?
Answers: 1
question
Computers and Technology, 23.06.2019 03:00
Jason, samantha, ravi, sheila, and ankit are preparing for an upcoming marathon. each day of the week, they run a certain number of miles and write them into a notebook. at the end of the week, they would like to know the number of miles run each day, the total miles for the week, and average miles run each day. write a program to them analyze their data. your program must contain parallel arrays: an array to store the names of the runners and a two-dimensional array of five rows and seven columns to store the number of miles run by each runner each day. furthermore, your program must contain at least the following functions: a function to read and store the runners’ names and the numbers of miles run each day; a function to find the total miles run by each runner and the average number of miles run each day; and a function to output the results. (you may assume that the input data is stored in a file and each line of data is in the following form: runnername milesday1 milesday2 milesday3 milesday4 milesday5 milesday6 milesday7.)
Answers: 3
question
Computers and Technology, 24.06.2019 02:00
Write an expression that will cause the following code to print "equal" if the value of sensorreading is "close enough" to targetvalue. otherwise, print "not equal". ex: if targetvalue is 0.3333 and sensorreading is (1.0/3.0), output is:
Answers: 1
question
Computers and Technology, 24.06.2019 02:30
Which option completes the explanation for conflict of interest in an organization
Answers: 1
You know the right answer?
Modify the guessing-game program so that the user thinks of a number that the computer must guess.
Questions
question
Computers and Technology, 13.03.2020 00:59
question
Mathematics, 13.03.2020 00:59
Questions on the website: 13722359