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
32 changes: 32 additions & 0 deletions Project-61-Guess The Number/guess_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import random

def guess_the_number():
print("Welcome to the Guess the Number Game!")
print("I'm thinking of a number between 1 and 100.")
secret_number = random.randint(1, 100)
attempts = 0

while True:
try:
guess = int(input("\nEnter your guess (1–100): "))
attempts += 1
if guess < 1 or guess > 100:
print("Please guess within the range 1–100.")
continue
if guess < secret_number:
print("Too low! Try a higher number")
elif guess > secret_number:
print("Too high! Try a lower number")
else:
print(f" Correct! You guessed it in {attempts} attempts.")
break

except ValueError:
print("Please enter a valid number.")
play_again = input("\nDo you want to play again? (y/n): ").lower()
if play_again == 'y':
guess_the_number()
else:
print("Thanks for playing!")
if __name__ == "__main__":
guess_the_number()
16 changes: 16 additions & 0 deletions Project-61-Guess The Number/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## How It Works
* The computer picks a random number between 1 and 100.

* You keep guessing until you find the correct number.

* It tells you whether to go higher or lower.

* Once you guess correctly, it shows how many attempts you took.

* You can play again without restarting the program.

## Optional Upgrades To The Code
* Add difficulty levels (Easy: 1–50, Hard: 1–500)
* Track best score (minimum attempts)

--- ENJOY THE GAME!---