Skip to content

Instantly share code, notes, and snippets.

@Nalisarc
Created January 23, 2016 06:08
Show Gist options
  • Save Nalisarc/09529ca4e0649642fef2 to your computer and use it in GitHub Desktop.
Save Nalisarc/09529ca4e0649642fef2 to your computer and use it in GitHub Desktop.
from random import randint
import sys
number_range = [1,100]
def number_gen(number_range):
""" Generates the number to guess"""
return randint(number_range[0],number_range[1])
def main():
"""the main module!"""
end = False
while end == False:
number = number_gen(number_range)
responces = []
while 0 not in responces:
responces.append(guesser(number))
else:
print 'it took you {0} guesses!'.format(len(responces))
r = raw_input('Correct! Play again? (y/n)')
if r == 'n':
end = True
elif r == 'y':
number = number_gen(number_range)
responces = []
continue
else:
print 'that\'s not what I was expecting'
continue
def guesser(random_number):
"""takes user input and tests it against the number"""
try:
guess = int(raw_input('Your Number: '))
if guess == random_number:
return 0 #the win code!
else:
if guess > random_number:
print 'too high'
else:
print 'too low'
return 1 #the lose code!
except TypeError:
print 'That\'s not a number!'
return 2 #error code!
if __name__ == '__main__':
main()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment