<gh_stars>0
import random


def guess(x):
    random_number = random.randint(1, x)
    guess = 0
    while guess != random_number:
        guess = int(input(
            f"Python generated a lucky number for you. It's your turn to GUESS the number now! Hint: Number is between 1 and {x}: "))
        if guess < random_number:
            print(
                "Sorry! Try again with a higher number!")
        elif guess > random_number:
            print(
                "Sorry! Try again with a smaller number!")

    print(
        f"Your guess is correct!The random number generated by Python was {random_number}")


def computer_guess():
    computer_guess = 0
    my_secret_number = 1
    print("Think of a number between 1 and 10")
    input("Hit enter when you are ready!")
    computer_guess = random.randint(1, 10)
    while(computer_guess != my_secret_number):
        user_response = input(
            f"Is your secret number = {computer_guess}?(Y/N)")
        if user_response == "N" or user_response == "n":
            if(computer_guess < 10 and computer_guess > 0):
                user_response1 = input(
                    f"Is your secret number > {computer_guess}?(Y/N)")
                if user_response1 == "Y" or user_response1 == "y":
                    computer_guess += 1
                elif user_response1 == "N" or user_response1 == "n":
                    computer_guess -= 1
            elif computer_guess < 10 or computer_guess > 0:
                print("I have exceeded maximum tries, I give up!")
                break
        elif user_response == "Y" or user_response == "y":
            my_secret_number = computer_guess
            print(
                f"I am a genius computer!Your secret number was {computer_guess}!!!")
            break


def smarter_computer_guess():
    print("*******Guessing Game*********")
    print("Let the computer guess the secret number in your mind!")
    print("Think of a number between 1 and 100")
    input("Press ENTER when you are ready!!!")
    secret_number = -1
    computer_guess = 0
    starting_number_in_range = 1
    ending_number_in_range = 100
    while(computer_guess != secret_number):
        computer_guess = random.randint(
            starting_number_in_range, ending_number_in_range)
        guessed_the_number = input(
            f"Is your secret number = {computer_guess}?(Y/N): ").lower()
        if guessed_the_number == "N" or guessed_the_number == "n":
            user_response = input(
                f"Is your secret number > {computer_guess}?(Y/N): ").lower()
            if user_response == "y":
                starting_number_in_range = computer_guess+1
                computer_guess = random.randint(
                    starting_number_in_range, ending_number_in_range)
            elif user_response == "n":
                ending_number_in_range = computer_guess
                computer_guess = random.randint(
                    starting_number_in_range, ending_number_in_range)
        elif guessed_the_number == "y":
            secret_number = computer_guess
            print(
                f"I am a genius computer!!!Your secret number was {computer_guess}")
        else:
            print("That's an invalid response, PRESS Y for Yes OR N for No :)")


# guess(88)
# computer_guess()
smarter_computer_guess()

import random


def guess(x):
    random_number = random.randint(1, x)
    guess = 0
    while guess != random_number:
        guess = int(input(
            f"Python generated a lucky number for you. It's your turn to GUESS the number now! Hint: Number is between 1 and {x}: "))
        if guess < random_number:
            print(
                "Sorry! Try again with a higher number!")
        elif guess > random_number:
            print(
                "Sorry! Try again with a smaller number!")

    print(
        f"Your guess is correct!The random number generated by Python was {random_number}")


def computer_guess():
    computer_guess = 0
    my_secret_number = 1
    print("Think of a number between 1 and 10")
    input("Hit enter when you are ready!")
    computer_guess = random.randint(1, 10)
    while(computer_guess != my_secret_number):
        user_response = input(
            f"Is your secret number = {computer_guess}?(Y/N)")
        if user_response == "N" or user_response == "n":
            if(computer_guess < 10 and computer_guess > 0):
                user_response1 = input(
                    f"Is your secret number > {computer_guess}?(Y/N)")
                if user_response1 == "Y" or user_response1 == "y":
                    computer_guess += 1
                elif user_response1 == "N" or user_response1 == "n":
                    computer_guess -= 1
            elif computer_guess < 10 or computer_guess > 0:
                print("I have exceeded maximum tries, I give up!")
                break
        elif user_response == "Y" or user_response == "y":
            my_secret_number = computer_guess
            print(
                f"I am a genius computer!Your secret number was {computer_guess}!!!")
            break


def smarter_computer_guess():
    print("*******Guessing Game*********")
    print("Let the computer guess the secret number in your mind!")
    print("Think of a number between 1 and 100")
    input("Press ENTER when you are ready!!!")
    secret_number = -1
    computer_guess = 0
    starting_number_in_range = 1
    ending_number_in_range = 100
    while(computer_guess != secret_number):
        computer_guess = random.randint(
            starting_number_in_range, ending_number_in_range)
        guessed_the_number = input(
            f"Is your secret number = {computer_guess}?(Y/N): ").lower()
        if guessed_the_number == "N" or guessed_the_number == "n":
            user_response = input(
                f"Is your secret number > {computer_guess}?(Y/N): ").lower()
            if user_response == "y":
                starting_number_in_range = computer_guess+1
                computer_guess = random.randint(
                    starting_number_in_range, ending_number_in_range)
            elif user_response == "n":
                ending_number_in_range = computer_guess
                computer_guess = random.randint(
                    starting_number_in_range, ending_number_in_range)
        elif guessed_the_number == "y":
            secret_number = computer_guess
            print(
                f"I am a genius computer!!!Your secret number was {computer_guess}")
        else:
            print("That's an invalid response, PRESS Y for Yes OR N for No :)")


# guess(88)
# computer_guess()
smarter_computer_guess()
# guess(88) # computer_guess()