From 094922e96d68c32dbb2a8754ba3748a8521141c1 Mon Sep 17 00:00:00 2001 From: 1SKC1 Date: Wed, 29 Jul 2026 21:15:15 +0530 Subject: [PATCH 1/2] number-guesser --- Number_Guesser.py | 15 +++++++++++++++ README.md | 1 + 2 files changed, 16 insertions(+) create mode 100644 Number_Guesser.py diff --git a/Number_Guesser.py b/Number_Guesser.py new file mode 100644 index 00000000000..bdbd93306e2 --- /dev/null +++ b/Number_Guesser.py @@ -0,0 +1,15 @@ +import random + +max_range = int(input("Enter the maximum range for the number guessing game: ")) +secret_number = random.randint(1, max_range) +number_guessed = False + +while not number_guessed: + guess = int(input(f"Guess a number between 1 and {max_range}: ")) + if guess < secret_number: + print("Too low! Try again.") + elif guess > secret_number: + print("Too high! Try again.") + else: + print(f"Congratulations! You've guessed the correct number! It was {secret_number}.") + number_guessed = True \ No newline at end of file diff --git a/README.md b/README.md index 78bf507a22f..ec7b3886bfe 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ Feel free to explore the scripts and use them for your learning and automation n 41. [Extract Thumbnail From Video](https://github.com/geekcomputers/Python/tree/ExtractThumbnailFromVideo) - Extract Thumbnail from video files 42. [How to begin the journey of open source (first contribution)](https://www.youtube.com/watch?v=v2X51AVgl3o) - First Contribution of open source 43. [smart_file_organizer.py](https://github.com/sangampaudel530/Python2.0/blob/main/smart_file_organizer.py) - Organizes files in a directory into categorized subfolders based on file type (Images, Documents, Videos, Audios, Archives, Scripts, Others). You can run it once or automatically at set intervals using the `--path` and `--interval` options. +44. [Number_Guesser.py](https://github.com/1SKC1/Python.git) - A basic beginner friendly number guesser game with the user-specified range
_**Note**: The content in this repository belongs to the respective authors and creators. I'm just providing a formatted README.md for better presentation. From be636588fa57e4498e99a6ed890a175fa8786241 Mon Sep 17 00:00:00 2001 From: 1SKC1 Date: Wed, 29 Jul 2026 21:30:56 +0530 Subject: [PATCH 2/2] number-guesser --- Number_Guesser.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/Number_Guesser.py b/Number_Guesser.py index bdbd93306e2..f6e7f9da2c4 100644 --- a/Number_Guesser.py +++ b/Number_Guesser.py @@ -1,15 +1,31 @@ import random - +print(""" +=================================================================== + WELCOME TO THE NUMBER GUESSER GAME! +===================================================================""") max_range = int(input("Enter the maximum range for the number guessing game: ")) secret_number = random.randint(1, max_range) +# Flag variable to track if the number has been guessed or not number_guessed = False - +attempts = 0 while not number_guessed: - guess = int(input(f"Guess a number between 1 and {max_range}: ")) - if guess < secret_number: - print("Too low! Try again.") - elif guess > secret_number: - print("Too high! Try again.") - else: - print(f"Congratulations! You've guessed the correct number! It was {secret_number}.") - number_guessed = True \ No newline at end of file + try: + # To make sure the given input is an integer + guess = int(input(f"Guess a number between 1 and {max_range}: ")) + if guess < secret_number: + print("Too low! Try again.") + attempts += 1 # counts the number of incorrect attempts + elif guess > secret_number: + print("Too high! Try again.") + attempts += 1 # counts the number of incorrect attempts + else: + print(f"Congratulations! You've guessed the correct number! It was {secret_number}.\n") + print(f"Number of attempts: {attempts}") + number_guessed = True #Breaks the loop if the number is guessed correctly + + except ValueError: # prevents humanoid error if the user inputs a non-integer value + print("Invalid input! Please enter a valid integer.") +print(""" +=================================================================== + THANK YOU FOR PLAYING! +===================================================================""") \ No newline at end of file