The “Number Guessing Game” is an engaging Python program that challenges the player to guess a randomly generated number within a specified range. In this game, the player has the option to choose between two difficulty levels: “Easy” and “Hard.” The primary objective is to guess the secret number with a limited number of attempts, promoting strategic thinking and problem-solving. Below is a detailed program description:
- The program generates a random number between 1 and 100.
- The player chooses a difficulty level:
- “Easy” level allows the player 10 lives (guesses).
- “Hard” level allows the player only 5 lives (guesses).
- The player attempts to guess the secret number within the allotted lives.
- After each guess, the program provides feedback on whether the guessed number is higher or lower than the secret number.
- The game continues until the player either guesses the correct number or exhausts all allowed attempts.
- Initialization: The program initializes the game by selecting a random number within the specified range and setting the initial number of attempts based on the chosen difficulty level.
- User Interaction: The player interacts with the program through the console. They choose a difficulty level and enter their guesses.
- Input Validation: The program ensures that the player’s input is valid, rejecting non-numeric entries and guesses outside the specified range.
- Game Logic: The core of the program is the game logic that compares the player’s guesses with the secret number and provides feedback. It also keeps track of the number of lives remaining.
- Outcome: The game ends when one of the following conditions is met:
- The player correctly guesses the secret number.
- The player exhausts all allowed lives without guessing the secret number.
- Feedback: At the end of the game, the program provides feedback, including whether the player won or lost, the actual secret number, and the number of lives used