# # Play a number guessing game with the user. The computer will pick a target # number that the user is trying to guess in as few guesses as possible. # import random # # Pick the target value that the user is trying to guess. # lower_limit = 1 upper_limit = 100 target = random.randrange(lower_limit, upper_limit + 1) # # Read a guess from the user and count that the user guessed a value. # guess = int(input(f"Enter a guess between {lower_limit} and {upper_limit}: ")) while guess < lower_limit or guess > upper_limit: print("That wasn't valid guess... try again...") guess = int(input(f"Enter a guess between {lower_limit} and {upper_limit}: ")) count = 1 # While the user's guess is different from the target number... while guess != target: # # Report if the guess was too high or too low # if guess > target: print("Too high!") upper_limit = guess - 1 else: print("Too low!") lower_limit = guess + 1 # # Read another guess from the user and count that the user guessed a value. # guess = int(input(f"Enter a guess between {lower_limit} and {upper_limit}: ")) while guess < lower_limit or guess > upper_limit: print("That wasn't valid guess... try again...") guess = int(input(f"Enter a guess between {lower_limit} and {upper_limit}: ")) count = count + 1 # # Report that the user found the target value and the user's score. # print(f"That's correct!!!! And it only took you {count} guesses.")