Untitled
unknown
plain_text
2 years ago
2.9 kB
8
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") # ask if user wants to play again play_again = input("Do you want to play again? (yes/no)").casefold() if play_again == "yes": # reset the game if user wants to play again low = 1 high = 1000 print(f"Please think of a number between {low} and {high}:") input("Press any button to continue: ") guesses = 1 continue else: # end the game if user does not want to play again print("Thank you for playing!") break 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") # ask if user wants to play again play_again = input("Do you want to play again? (yes/no)").casefold() if play_again == "yes": # reset the game if user wants to play again low = 1 high = 1000 print(f"Please think of a number between {low} and {high}:") input("Press any button to continue: ") guesses = 1 continue else: # end the game if user does not want to play again print("Thank you for playing!") 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 += 1
Editor is loading...