From 592fc988511980bf75e51de415b5fd151c34e6a3 Mon Sep 17 00:00:00 2001 From: "[Shreyash Jadhav]" Date: Mon, 23 Nov 2026 21:20:21 +0530 Subject: [PATCH] Add number guessing game --- Guess the Number/Readme.md | 0 Guess the Number/guessthenumber.py | 39 ++++++++++++++++++++++++++++++ Guess the Number/requirements.txt | 0 3 files changed, 39 insertions(+) create mode 100644 Guess the Number/Readme.md create mode 100644 Guess the Number/guessthenumber.py create mode 100644 Guess the Number/requirements.txt diff --git a/Guess the Number/Readme.md b/Guess the Number/Readme.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Guess the Number/guessthenumber.py b/Guess the Number/guessthenumber.py new file mode 100644 index 00000000000..9bbd8bcf49d --- /dev/null +++ b/Guess the Number/guessthenumber.py @@ -0,0 +1,39 @@ + +""" +Module Name: Guess The Number +Description: Guess a randomly generated number between 1 and 100 +Author: Shreyinnit +Date: 2004-10-07 +""" + +import random + + +def guess_the_number(): + """ + Generate a random number and let the user guess it. + + Returns: + None + """ + number = random.randint(1, 100) + attempts = 0 + + print("Guess the number between 1 and 100!") + + while True: + guess = int(input("Enter your guess: ")) + attempts += 1 + + if guess < number: + print("Higher! Try again.") + elif guess > number: + print("Lower! Try again.") + else: + print("Congratulations! You guessed the number.") + print("Total attempts:", attempts) + break + + +if __name__ == "__main__": + guess_the_number() diff --git a/Guess the Number/requirements.txt b/Guess the Number/requirements.txt new file mode 100644 index 00000000000..e69de29bb2d