import random rg = 0 rounds = 3 user_score = 0 AI_score = 0 round = 1 # Game description print("The Take-Away Game") name = input('Enter player name: ') print("Welcome", name, "!" "In this game, there is a randomly generated number between 1 - 1000. The rules are as follows: You have 10 tries to guess the number. The AI gains a point if you cannot guess the number in 10 guesses and you gain a point if you can. The game is best out of 3, so the first person to get 2 points wins. The AI will tell you if your guess is higher or lower than the number.") # Start of game while user_score < 2 and AI_score < 2: number = random.randint(1, 1000) round_win = False g = rg print('Round', round) print(name, 'score is', user_score) print('AI score is', AI_score) # Loop for guesses within a round while not round_win and g < 10: print("Guess", g + 1) guess = int(input("What is your guess? ")) if 0 < guess < 1001: if guess == number: print("You guessed correctly!") round_win = True user_score += 1 elif guess < number: print("Higher!") g += 1 elif guess > number: print("Lower!") g += 1 else: print("Invalid number, try again.") # Check if player lost the round if not round_win: print("You lost this round.") AI_score += 1 # End of round, display round results print("End of round", round, '.', name,'score:', user_score, "AIscore:", AI_score) round += 1 # Overall game winner if AI_score > 1: print("You lost the game. Better luck next time!") break elif user_score > 1: print("You won! Good job!") break