diff --git a/Project-61-Guess The Number/guess_game.py b/Project-61-Guess The Number/guess_game.py new file mode 100644 index 0000000..353c17d --- /dev/null +++ b/Project-61-Guess The Number/guess_game.py @@ -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() diff --git a/Project-61-Guess The Number/readme.md b/Project-61-Guess The Number/readme.md new file mode 100644 index 0000000..60bacf3 --- /dev/null +++ b/Project-61-Guess The Number/readme.md @@ -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!--- \ No newline at end of file