Created
March 28, 2017 09:31
-
-
Save NimJ/a3da0e2a615fe6b6d2332bd1d3fed6d6 to your computer and use it in GitHub Desktop.
Guessing Game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def guessing_game(self): | |
| import random | |
| try: | |
| number = random.randint(1,9) | |
| count =0 | |
| x = int(input('guess the number \n ')) | |
| while x != number: | |
| if x > number: | |
| print 'high guess try again' | |
| count +=1 | |
| x = int(input('guess the number \n ')) | |
| elif x < number: | |
| print ' low guess try again' | |
| count +=1 | |
| x = int(input('guess the number \n ')) | |
| else: | |
| break | |
| print ' you guessed the number {0} in {1} chances'.format(number,count+1) | |
| except NameError: | |
| print ' Please enter valid number' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment