Now we will prompt the user to enter his name and store it to a variable named player_name. Next, we will use the random module to generate a number between 1 to 10 and store it in a variable named number. To generate a random number we will use a Python module named random to use this module in our program, we first need to import it. Now, open your favorite text editor and start coding.įirst, we will create a file a new file named game.py from our text editor. ![]() In this article, we will guide you through each step of making this interactive guessing game in Python. ![]() Okay! Abhijeet I am Guessing a number between 1 and 10: This is how the game looks in action, Hello, What's your name? When the user guess matches the number computer will print the answer along with the number of attempts. This is going to be a simple guessing game where the computer will generate a random number between 1 to 10, and the user has to guess it in 5 attempts.īased on the user's guess computer will give various hints if the number is high or low. Today we are going to make an interactive guessing game in Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |