diff --git a/examples/guessing_game.py b/examples/guessing_game.py index 5c27a5443f..1d7bb3aeec 100644 --- a/examples/guessing_game.py +++ b/examples/guessing_game.py @@ -5,7 +5,9 @@ def guessing_game(): secret_number = random.randrange(101) - while True: + attempts = 3 + + while attempts > 0: guess = input("Input your guess: ") try: @@ -23,6 +25,10 @@ def guessing_game(): print("Too small!") else: print("Too big!") + attempts -= 1 + if attempts == 0: + print(f"You have {attempts} left!") + break if __name__ == '__main__': - guessing_game() \ No newline at end of file + guessing_game()