- Get link
- Other Apps
Posted by
Naveen M K
on
- Get link
- Other Apps
Yeah! It's been a long wish for everybody I believe has wished to create a game for a desktop or a mobile phone. It's a bit easy if you programming and have good logic. In the pace of using Python a programming language, I am going to help you out in creating a new game. This game is purely for beginner's who are learning python. This is a game is to generate a random number and store it. Ask the user for the number to be guessed and give hints. By this way, the user can guess the number.
Algorithm
- Create a random number using the random module in python.
- Save number to a variable.
- Ask for input from the user. Check whether it is equal to number saved. If it is equal check for playing again.
- Elseask continuously the number by giving hints about whether the number is higher or lower.
- That's Not so hard.
Coding
1 2 3 4 5 6 7 8 9 10 | import random a=random.randint(1,100) b=int(input('Guess a number between 1 and 100 inclusive')) while b!=a: if a<b: print('The number is less') else: print('The number is more') b=int(input('Sorry, enter again')) print('Congradulation, You have Found The number to be',a) |
Explanation
Here, I used the random module which is default with, Python installation. Using the randint() function in that helps us to generate a random number. This asking user is bit easy one. I just used a while loop to check and it worked!Hope this one helps.
Comments
You can fix the coding part.
ReplyDelete