Skip to content

Instantly share code, notes, and snippets.

@NimJ
Created March 28, 2017 09:31
Show Gist options
  • Select an option

  • Save NimJ/a3da0e2a615fe6b6d2332bd1d3fed6d6 to your computer and use it in GitHub Desktop.

Select an option

Save NimJ/a3da0e2a615fe6b6d2332bd1d3fed6d6 to your computer and use it in GitHub Desktop.
Guessing Game
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