import random

compyGuess= random.randrange(1,20)

def computerGuess():
    return random.randrange(1,20)

print ("I am thinking of a number between 1 and 20.")

def theNumber():
    try:
        usrin = int(input("Can you guess what it is?\n"))
        if not ( usrin >= 1 and usrin <=20):
            raise ValueError()
    except ValueError:
        print ("Please type in a whole number between 1 and 20.")
        return False
    else:
        return usrin
    


def theGame():
    usrNum = theNumber()
    if usrNum != False:
        if compyGuess == usrNum:
            print ("Right! You got it!")
            return newGame()
        else:
            if usrNum < compyGuess + 3 and usrNum > compyGuess - 3:
                print ("Hot.")
                return True
            else:
                print ("Cold.")
                if usrNum > compyGuess:
                    print ("Too High.")
                else:
                    print ("Too Low.")
                return True

def newGame():
    try:
        playagain = str(input("Play again? Type \"Yes\" to continue or anything else to exit.\n"))
        if not (playagain == "Yes"):
            raise ValueError()
    except ValueError:
        return False
    else:
        global compyGuess
        compyGuess=computerGuess()
        return True

while True:
    if theGame() == False:
        break
