Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice
- global list
- list = list(range(0,11))
- print (list)
- global cache
- cache = []
- print ("Write down a number anywhere from 1-10.\nThe computer will try to guess your number.")
- def guess():
- global guess
- guess = choice(list)
- if guess in cache:
- guess()
- else:
- pass
- print (guess)
- cache.append(guess)
- def check():
- global check
- check = input("Was " + str(guess) + " the number? (y, n) ").lower()
- if check == "n":
- global wrong
- wrong = input("Lower or higher? ").lower
- elif check == "y":
- playAgain = input ("I guessed the number! Play again? (y, n)")
- if playAgain == "y":
- main()
- if playAgain == "n":
- exit()
- else:
- print("Please answer in the format 'y' or 'n'")
- def reguess():
- if wrong == "lower":
- reguess = choice(list < guess)
- check(reguess)
- elif wrong == "higher":
- check(reguess)
- reguess = choice(list > guess)
- def cacheCheck():
- if reguess in cache:
- reguess()
- else:
- pass
- def main():
- guess()
- check()
- reguess()
- cacheCheck()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement