import random as rand


number = rand.randrange(0,20)

print(number)

user_input = input("Guess the random number generated by me between 0-20: ")
#input_value = False

def input_check(user_input , input_value = False):
    #global user_input
    if (user_input.isdigit() and user_input != "" and user_input != " "):
        input_value = True
        return input_value
    else:
        get_int_input(input_value)
        #user_input = user_input1
        return user_input

def get_int_input(input_value):
    global user_input
    while(input_value == False):
        print("This game can only be paid if the input is a number. Lets try again")
        user_input = input("Guess the random number generated by me between 0-20: ")
        if (user_input.isdigit()):
            input_value = True
        else:
            input_value = False
    return int(user_input)
input_check(user_input)

while(int(user_input) != number):
    if(int(user_input) > number):
        if( int(user_input) - number < 3 ):
            print("You are very close. Keep trying")
            user_input = input("Guess the random number again: ")
            input_check(user_input)
        else:
            print("You have guessed too high. Try again")
            user_input = input("Guess the random number again: ")
            input_check(user_input)
    elif(int(user_input) < number):
        if (int(user_input) - number > -3):
            print("You are very close. Keep trying")
            user_input = input("Guess the random number again: ")
            input_check(user_input)
        else:
            print("You have guessed too low. Try again")
            user_input = input("Guess the random number again: ")
            input_check(user_input)

print("You have successfully guessed the number generated by me, which was {}".format(number))

