Advertisement
Guest User

Untitled

a guest
Nov 1st, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. from random import choice
  2.  
  3. global list
  4. list = list(range(0,11))
  5. print (list)
  6.  
  7. global cache
  8. cache = []
  9.  
  10. print ("Write down a number anywhere from 1-10.\nThe computer will try to guess your number.")
  11.  
  12. def guess():
  13.     global guess
  14.     guess = choice(list)
  15.     if guess in cache:
  16.         guess()
  17.     else:
  18.         pass
  19.     print (guess)
  20.     cache.append(guess)
  21.    
  22. def check():
  23.     global check
  24.     check = input("Was " + str(guess) + " the number? (y, n) ").lower()
  25.     if check == "n":
  26.         global wrong
  27.         wrong = input("Lower or higher? ").lower
  28.     elif check == "y":
  29.         playAgain = input ("I guessed the number! Play again? (y, n)")
  30.         if playAgain == "y":
  31.             main()
  32.         if playAgain == "n":
  33.             exit()
  34.     else:
  35.         print("Please answer in the format 'y' or 'n'")
  36.  
  37. def reguess():
  38.     if wrong == "lower":
  39.         reguess = choice(list < guess)
  40.         check(reguess)
  41.     elif wrong == "higher":
  42.         check(reguess)
  43.         reguess = choice(list > guess)
  44.  
  45. def cacheCheck():
  46.     if reguess in cache:
  47.         reguess()
  48.     else:
  49.         pass
  50.  
  51. def main():
  52.     guess()
  53.     check()
  54.     reguess()
  55.     cacheCheck()
  56.  
  57. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement