From dbafaf7d326e12b0e265f61608fc3e6ee9a5517a Mon Sep 17 00:00:00 2001 From: "Gupta, Sunny" Date: Sat, 5 Oct 2024 21:13:24 +0530 Subject: [PATCH] enhancements --- {Game Galore => Game-Galore}/README.md | 0 Game-Galore/guessing_game.py | 36 +++++++++++++++++++ .../text_adventure.py | 0 3 files changed, 36 insertions(+) rename {Game Galore => Game-Galore}/README.md (100%) create mode 100644 Game-Galore/guessing_game.py rename {Game Galore => Game-Galore}/text_adventure.py (100%) diff --git a/Game Galore/README.md b/Game-Galore/README.md similarity index 100% rename from Game Galore/README.md rename to Game-Galore/README.md diff --git a/Game-Galore/guessing_game.py b/Game-Galore/guessing_game.py new file mode 100644 index 0000000..11acc3c --- /dev/null +++ b/Game-Galore/guessing_game.py @@ -0,0 +1,36 @@ +import random + +def guessing_game(): + print("Welcome to the Number Guessing Game!") + lower_bound = 1 + upper_bound = 100 + secret_number = random.randint(lower_bound, upper_bound) + attempts = 0 + max_attempts = 10 + + print(f"I've selected a number between {lower_bound} and {upper_bound}. You have {max_attempts} attempts to guess it.") + + while attempts < max_attempts: + try: + guess = int(input("Enter your guess: ")) + attempts += 1 + + if guess < lower_bound or guess > upper_bound: + print(f"Please guess a number between {lower_bound} and {upper_bound}.") + continue + + if guess < secret_number: + print("Too low!") + elif guess > secret_number: + print("Too high!") + else: + print(f"Congratulations! You've guessed the number {secret_number} in {attempts} attempts.") + break + except ValueError: + print("Invalid input. Please enter an integer.") + + if attempts == max_attempts: + print(f"Sorry, you've used all your attempts. The secret number was {secret_number}.") + +if __name__ == "__main__": + guessing_game() diff --git a/Game Galore/text_adventure.py b/Game-Galore/text_adventure.py similarity index 100% rename from Game Galore/text_adventure.py rename to Game-Galore/text_adventure.py