From d7dd5507f24d795ba8499616e347ebc992c87453 Mon Sep 17 00:00:00 2001 From: MasettoJr Date: Wed, 6 May 2026 20:49:42 -0300 Subject: [PATCH 1/3] Replay feature and option validation added --- guessing-game/guessing-game.py | 77 ++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/guessing-game/guessing-game.py b/guessing-game/guessing-game.py index 5ee3093..1fcc6d3 100644 --- a/guessing-game/guessing-game.py +++ b/guessing-game/guessing-game.py @@ -11,29 +11,54 @@ # Set the number of allowed attempts attempts = 7 -# Game loop -while attempts > 0: - try: - # Ask the user for their guess - guess = int(input("Enter your guess: ")) - - # Check if the guess is correct - if guess == secret_number: - print("🎉 Congratulations! You guessed the number!") - break - elif guess < secret_number: - print("Too low. Try a higher number.") - else: - print("Too high. Try a lower number.") - - # Decrease remaining attempts - attempts -= 1 - print(f"Attempts left: {attempts}\n") - - except ValueError: - # Handle non-integer input - print("Invalid input. Please enter a number.\n") - -# If no attempts are left -if attempts == 0: - print(f"❌ Game over! The number was {secret_number}. Better luck next time.") +# Loop that runs the game indefinitely until the player chooses to quit +while True: + # Game loop + while attempts > 0: + try: + # Ask the user for their guess + guess = int(input("Enter your guess: ")) + + # Check if the guess is correct + if guess == secret_number: + print("🎉 Congratulations! You guessed the number!") + break + elif guess < secret_number: + print("Too low. Try a higher number.") + else: + print("Too high. Try a lower number.") + + # Decrease remaining attempts + attempts -= 1 + print(f"Attempts left: {attempts}\n") + + except ValueError: + # Handle non-integer input + print("Invalid input. Please enter a number.\n") + + # If no attempts are left + if attempts == 0: + print(f"❌ Game over! The number was {secret_number}. Better luck next time.") + + # Variable to determine whether the game should keep running or stop + play_again = input("\nDo you wanna play again? Y/N: ").upper().strip() + + # Option validation + while play_again not in ("Y", "N"): + print("\nInvalid option!") + play_again = input("\nDo you wanna play again? Y/N: ").upper().strip() + + print() + + # Reset attempts when player chooses to play again + if play_again == "Y": + attempts = 7 + + # Generate a random number between 1 and 100 + secret_number = random.randint(1, 100) + print("Your attempts have been reset to 7!") + continue + else: + print("Game finished. Thank you!") + break + From f07db8de6aa792600121a9c1970f2361fb98ab2f Mon Sep 17 00:00:00 2001 From: MasettoJr Date: Wed, 6 May 2026 20:53:08 -0300 Subject: [PATCH 2/3] Revert "Replay feature and option validation added" This reverts commit d7dd5507f24d795ba8499616e347ebc992c87453. --- guessing-game/guessing-game.py | 77 ++++++++++++---------------------- 1 file changed, 26 insertions(+), 51 deletions(-) diff --git a/guessing-game/guessing-game.py b/guessing-game/guessing-game.py index 1fcc6d3..5ee3093 100644 --- a/guessing-game/guessing-game.py +++ b/guessing-game/guessing-game.py @@ -11,54 +11,29 @@ # Set the number of allowed attempts attempts = 7 -# Loop that runs the game indefinitely until the player chooses to quit -while True: - # Game loop - while attempts > 0: - try: - # Ask the user for their guess - guess = int(input("Enter your guess: ")) - - # Check if the guess is correct - if guess == secret_number: - print("🎉 Congratulations! You guessed the number!") - break - elif guess < secret_number: - print("Too low. Try a higher number.") - else: - print("Too high. Try a lower number.") - - # Decrease remaining attempts - attempts -= 1 - print(f"Attempts left: {attempts}\n") - - except ValueError: - # Handle non-integer input - print("Invalid input. Please enter a number.\n") - - # If no attempts are left - if attempts == 0: - print(f"❌ Game over! The number was {secret_number}. Better luck next time.") - - # Variable to determine whether the game should keep running or stop - play_again = input("\nDo you wanna play again? Y/N: ").upper().strip() - - # Option validation - while play_again not in ("Y", "N"): - print("\nInvalid option!") - play_again = input("\nDo you wanna play again? Y/N: ").upper().strip() - - print() - - # Reset attempts when player chooses to play again - if play_again == "Y": - attempts = 7 - - # Generate a random number between 1 and 100 - secret_number = random.randint(1, 100) - print("Your attempts have been reset to 7!") - continue - else: - print("Game finished. Thank you!") - break - +# Game loop +while attempts > 0: + try: + # Ask the user for their guess + guess = int(input("Enter your guess: ")) + + # Check if the guess is correct + if guess == secret_number: + print("🎉 Congratulations! You guessed the number!") + break + elif guess < secret_number: + print("Too low. Try a higher number.") + else: + print("Too high. Try a lower number.") + + # Decrease remaining attempts + attempts -= 1 + print(f"Attempts left: {attempts}\n") + + except ValueError: + # Handle non-integer input + print("Invalid input. Please enter a number.\n") + +# If no attempts are left +if attempts == 0: + print(f"❌ Game over! The number was {secret_number}. Better luck next time.") From 1be41c02bb1303badef93b7660d6efb758845d50 Mon Sep 17 00:00:00 2001 From: MasettoJr Date: Wed, 6 May 2026 20:54:47 -0300 Subject: [PATCH 3/3] Added replay and option validation --- guessing-game/guessing-game.py | 77 ++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/guessing-game/guessing-game.py b/guessing-game/guessing-game.py index 5ee3093..1fcc6d3 100644 --- a/guessing-game/guessing-game.py +++ b/guessing-game/guessing-game.py @@ -11,29 +11,54 @@ # Set the number of allowed attempts attempts = 7 -# Game loop -while attempts > 0: - try: - # Ask the user for their guess - guess = int(input("Enter your guess: ")) - - # Check if the guess is correct - if guess == secret_number: - print("🎉 Congratulations! You guessed the number!") - break - elif guess < secret_number: - print("Too low. Try a higher number.") - else: - print("Too high. Try a lower number.") - - # Decrease remaining attempts - attempts -= 1 - print(f"Attempts left: {attempts}\n") - - except ValueError: - # Handle non-integer input - print("Invalid input. Please enter a number.\n") - -# If no attempts are left -if attempts == 0: - print(f"❌ Game over! The number was {secret_number}. Better luck next time.") +# Loop that runs the game indefinitely until the player chooses to quit +while True: + # Game loop + while attempts > 0: + try: + # Ask the user for their guess + guess = int(input("Enter your guess: ")) + + # Check if the guess is correct + if guess == secret_number: + print("🎉 Congratulations! You guessed the number!") + break + elif guess < secret_number: + print("Too low. Try a higher number.") + else: + print("Too high. Try a lower number.") + + # Decrease remaining attempts + attempts -= 1 + print(f"Attempts left: {attempts}\n") + + except ValueError: + # Handle non-integer input + print("Invalid input. Please enter a number.\n") + + # If no attempts are left + if attempts == 0: + print(f"❌ Game over! The number was {secret_number}. Better luck next time.") + + # Variable to determine whether the game should keep running or stop + play_again = input("\nDo you wanna play again? Y/N: ").upper().strip() + + # Option validation + while play_again not in ("Y", "N"): + print("\nInvalid option!") + play_again = input("\nDo you wanna play again? Y/N: ").upper().strip() + + print() + + # Reset attempts when player chooses to play again + if play_again == "Y": + attempts = 7 + + # Generate a random number between 1 and 100 + secret_number = random.randint(1, 100) + print("Your attempts have been reset to 7!") + continue + else: + print("Game finished. Thank you!") + break +