Write a Python program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number.
sample run:
enter number to be guessed:88
output: you entered 88, and it took the program 3 iterations to guess.
import random number = random.randint(1, 100) guess = -1 count = 0 while guess != number: guess = int(input('enter number to be guessed:')) count += 1 if guess < number: print("Too low") elif guess > number: print("Too high") print("you entered {}, and it took the program {} iterations to guess.".format(guess, count))
Get Answers For Free
Most questions answered within 1 hours.