import random

user_score = ai_score = 0
max_chances = 10


name = input("What's your name? ")
print(f"Hey {name}, welcome to the game You have {max_chances} chances to guess the AIs number between 1 and 1000. Best of 3 rounds")


for round_num in range(1, 4):
    print(f"\nRound {round_num}")
    ai_number = random.randint(1, 1000)


    user_chances = max_chances
    while user_chances > 0:
        guess = int(input(f"Your guess ({user_chances} chances left): "))
        if guess == ai_number:
            user_score += 1
            print("Correct guess.")
            break
        elif guess > ai_number:
            print("To high Try again.")
        else:
            print("To low Try again.")
        user_chances -= 1


    ai_chances = max_chances
    while ai_chances > 0:
        ai_guess = random.randint(1, 1000)
        print(f"AI guesses: {ai_guess}")
        if ai_guess == ai_number:
            ai_score += 1
            print("AI got it right")
            break
        ai_chances -= 1


    print(f"Round {round_num} score: {name} {user_score} - AI {ai_score}")


if user_score > ai_score:
    print(f"Congratulations {name}! You won {user_score} to {ai_score}.")
elif ai_score > user_score:
    print(f"AI wins {ai_score} to {user_score}.")
else:
    print(f"It's a tie! {user_score} to {ai_score}.")