Ask the user to think of a number between zero and one hundred. Your goal is to guess the number in as few guesses as possible. The user will inform you if you guessed too high, low or correct. Start by always guessing the middle number 50. If the user informs you it’s too low, then try 75. If 50 was too high, then try 25. Always guess the middle of the range of numbers left. In doing so, the range of numbers will be cut in half after each guess. If done correctly, no more than 7 guesses are needed. Print out “you cheated” if you reach 7 guesses and are still wrong.

See Answers (1)

Accepted Answer

A program in Python that asks the user to think of a number between zero and one hundred and tries to guess the number in as few guesses as possible is given below:The Programimport randomimport math# Taking Inputslower = int(input("Enter Lower bound:- "))# Taking Inputsupper = int(input("Enter Upper bound:- "))# generating random number between# the lower and upperx = random.randint(lower, upper)print("\n\tYou've only ", round(math.log(upper - lower + 1, 2)), " chances to guess the integer!\n")# Initializing the number of guesses.count = 0# for calculation of minimum number of# guesses depends upon rangewhile count < math.log(upper - lower + 1, 2): count += 1 # taking guessing number as input guess = int(input("Guess a number:- ")) # Condition testing if x == guess:  print("Congratulations you did it in ",   count, " try")  # Once guessed, loop will break  break elif x > guess:  print("You guessed too small!") elif x < guess:  print("You Guessed too high!")# If Guessing is more than required guesses,# shows this output.if count >= math.log(upper - lower + 1, 2): print("\nThe number is %d" % x) print("\tBetter Luck Next time!")Read more about python programming here:https://brainly.com/question/26497128#SPJ1

Related Question in Computers and Technology