> For the complete documentation index, see [llms.txt](https://pda-assignments.consoleflare.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pda-assignments.consoleflare.com/python-for-data-analytics/1.python/3.python-projects/guess-the-number-game.md).

# Guess the Number Game

## **Create a game called 'Guess the number'. Let us go through the Rules one by one.**

&#x20;  **1. The computer will generate a Random Number.**

&#x20;  **2. Ask the user to guess the number in 10 chances.**

&#x20; **3. If the user guesses it right, Score him accordingly like if the user guesses in the first chance, the score is 100, in second chance score should be 90, and so on.**

4. **If the guess number is greater than the random number give him 'Hint: Choose a Lower Number' or less than the random number give him 'hint: Choose a Higher Number' or if the guess number is equal to random, No need to hint, just display score and end the game.**

&#x20;**5. Also show how many chances are left.**

&#x20;**6. if the user cannot guess the number, disclose the random number and end the game.**

<details>

<summary>Example</summary>

**`Guess the number : 60`**&#x20;

**`Hint : Choose a Lower Number`**&#x20;

**`---------------Number of Chances Left -------------->1`**&#x20;

**`Guess the number : 50`**&#x20;

**`Hint : Choose a Higher Number.`**&#x20;

**`---------------Number of Chances Left -------------->2`**&#x20;

**`Guess the number : 55`**&#x20;

**`Hint : Choose a Higher Number.`**&#x20;

**`---------------Number of Chances Left -------------->3`**&#x20;

**`Guess the number : 58`**&#x20;

**`You Won .`**&#x20;

**`Score : 70`**

</details>

<details>

<summary>Solution</summary>

```python
import random
random_number = random.randint(1,100) 
print(random_number)
chances = 1 
score = 110 
while(chances<=10): 
    guess_number = int(input('Guess the number : ')) 
    if(guess_number==random_number): 
        score = score - chances*10 
        print(f'You Won . Score : {score}') 
        break 
elif(guess_number>random_number): 
    print('Hint : Choose a Lower Number') 
else: 
    print('Hint : Choose a Higher Number.') 
    print(f'---------------Number of Chances Left -------->{chances}') 
    chances = chances + 1 
else: 
    print(f'Sorry ! You lost . You ran out of your chances. Random number was : {random_number}')
```

</details>
