Hello! Can somebody Help me please?

Here is this guessing game. I would like the player to try 2 times if he failed the game must stop.

import random

def guess(x):

    random_number = random.randint(1, x)

    guess = 0

   

    while guess != random_number:

        guess = int(input(f"Guess a number between 1 and {x}:  "))

    
        if guess < random_number:

            print("Sorry, guess again. Too low.")

        elif guess > random_number:

            print("Sorry, Too high.")

           

    print(f"Yay, congrats. You have guessed the number {random_number} correctly!!")

guess(10)

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

The first thing you need to do is keep track of the number of times the player tries to guess the number.

Which also means this probably won’t work:

Because you want the game to end after two wrong attempts, rather than a correct guess.

Thank you so much my friend