Untitled
unknown
plain_text
3 years ago
1.9 kB
7
Indexable
low = 1
high = 1000
print("Welcome to the game of Team A")
print(f"Please think of a number between {low} and {high}:")
input("Press any button to continue: ")
guesses =1
while True:
print(f"\nGuessing in the range of {low} and {high}")
guess = low + (high - low) //2
my_guess = input(f"My guess is {guess}"
"\nShould I guess higher or lower?"
"\nEnter 'up' or 'down' or 'c' if my guess is correct. Or press 'g' to guess manually: ")
if my_guess.casefold() =='up':
low = guess + 1
elif my_guess.casefold() == 'down':
high = guess - 1
elif my_guess.casefold() == 'c':
print(f"I got it in {guesses} guesses")
print(f"\nGuessing in the range of {low} and {high}")
print(f"Please think of a number between {low} and {high}:")
input("Press any button to continue: ")
guesses = 1
continue
elif my_guess.casefold() == 'g':
manual_guess = int(input("Enter your guess: "))
if manual_guess < low or manual_guess > high:
print(f"Your guess should be between {low} and {high}")
continue
else:
manual_input = input(f"Is {manual_guess} your number? (yes/no)")
if manual_input.casefold() == "yes":
print(f"I got it in {guesses} guesses")
break
elif manual_input.casefold() == "no":
high_or_low = "lower" if manual_guess < guess else "higher"
print(f"Your number is {high_or_low}.")
guesses += 1
continue
else:
print("Invalid input. Please enter 'yes' or 'no'")
continue
else:
print("Please enter only 'up', 'down', 'c', or 'g' ")
continue
guesses +=1Editor is loading...