subject
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

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:00, hailee232
What is a society that has moved to the internet rather than relying on physical media called
Answers: 2
image
Computers and Technology, 22.06.2019 19:20, SundaeSunday
Consider the following code snippet: #ifndef cashregister_h#define cashregister_hconst double max_balance = 6000000.0; class cashregister{public: cashregister(); cashregister(double new_balance); void set_balance(double new_balance); double get_balance() const; private: double balance[12]; }; double get_monthly_balance(cashregister bk, int month); #endifwhich of the following is correct? a)the header file is correct as given. b)the definition of max_balance should be removed since header files should not contain constants. c)the definition of cashregister should be removed since header files should not contain class definitions. d)the body of the get_monthly_balance function should be added to the header file.
Answers: 1
image
Computers and Technology, 22.06.2019 22:00, lgary9462
Perform the following tasks: a. create a class named testclass that holds a single private integer field and a public constructor. the only statement in the constructor is one that displays the message “constructing”. write a main()function that instantiates one object of the testclass. save the file as testclass. cpp in the chapter 08 folder. run the program and observe the results. b. write another main()function that instantiates an array of 10 testclass objects. save the file as test class array. c . run this program and observe the results.
Answers: 1
image
Computers and Technology, 23.06.2019 15:30, taapeters
Brian wants to conduct an online search with a certain phrase. he intends to use the words books that belong to the 1800s in his search. how should he use the word that in his search?
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 in other subjects: