Simple Number Guessing Game in Python

Here is a simple Python code for a number guessing game:

This code uses the random module to generate a random number between 1 and 100, which the player will need to guess. It starts by prompting the player to make a guess, which is stored as the variable guess. The code then enters a while loop which will continue until the player's guess matches the randomly generated answer.

Inside the while loop, the code checks if the player's guess is higher or lower than the answer. If the guess is higher, the code prints "Too high!" and if the guess is lower, it prints "Too low!". The player is then prompted to make another guess, and the tries variable is incremented by 1.

Once the player guesses the correct number, the while loop exits, and the code prints a message congratulating the player on guessing the number in a certain number of tries.

Hope this helps! Let me know if you have any questions.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.