random number
random number
1. Prompt the user to enter a lower and an upper bound. If the lower
bound is greater than the upper bound, swap them to ensure a valid
range.
- If the guess is too low, adjust the lower bound to be one more than the
guess.
- If the guess is too high, adjust the upper bound to be one less than the
guess.
6. End the game when the user guesses the correct number and display a
congratulatory message.
'''
import random
while True:
try:
lower, upper = upper, lower # swap if user enters the wrong order
for lower and upper
break
except ValueError:
while True:
try:
if guess == number:
break
lower = guess
print(f"Sorry! You guessed the wrong number and the new range is
between {lower} and {upper}")
else:
upper = guess
print(f"Sorry! You guessed the wrong number and the new range is
between {lower} and {upper}")
except ValueError: