Today we will make a number guessing game in python. A number guessing game is a user enters a number and it should match the number which the program has created.
Our number guessing game will little different the user will enter a number than if the number is wrong than the user will get a hint like your number is greater or lesser than the answer and the user will have 3 chances to answer the right answer.
It is a simple and easy project you should try to create this project on your own if you can’t than you can follow this article I will give the source code for this project.
If you are intrested in more projects like this than you can check out my projects that I have created at coderzway projects.
Let’s make a number guessing game in python
Contents
I hope you have knowledge of python basics and you have python installed on your machine if you don’t have python installed you can go to the python website and download – download python and remember to check add python to path while installing.
1. Create python file
Now first you need to create python file with .py extension you can go to any folder and create a python file and you need to open this file in a text editor I use vs code you can use any editor you can download vs code from here – download vs code.
2. Copy and paste
Now you have created the file now you can paste this code for number guessing game
How does this works
So I have used the random python module and it generates a random number between 1 to 15 you can increase this than asks for your input than it goes into the while loop checking if the answer is right or you have finished your chances if not it continues to ask the answer.
After this you can run this file by opening command prompt or terminal at the file location and type this in the command prompt python filename.py
This will run the file and this is the output
Output
How to use
1 – Enter a number and it will check if the number is correct
2 – If it is wrong you will get a hint and you have 3 chances
So this was number guessing game in python I know it was simple and easy but you can expand this project. If you want more projects do subscribe to coderzway newsletter and thank you for reading see you next time.
0 Comment