Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Number_Guesser.py
Original file line number Diff line number Diff line change
@@ -0,0 +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:
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!
===================================================================""")
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<hr>

_**Note**: The content in this repository belongs to the respective authors and creators. I'm just providing a formatted README.md for better presentation.