In [5]:
from random import randint
from IPython.display import clear_output
from time import sleep

totalMatch = 0
totalWin = 0
    
# -----------------------------------
# Creates the code for the randomizer

def randomizer():
    global totalWin
    global totalMatch
    randomNum = randint(0, 1000) # Picks a random number from 0 to 1000.
    for guesses in range(1,11):
        print("Attempt" + " {}" .format(guesses))
        myGuess = int(input("Enter a number here."))
        if myGuess > randomNum: # Hints if the number is lower or higher than the random number.
            print("The random number is lower than {}." .format(myGuess))
        if myGuess < randomNum:
            print("The random number is higher than {}." .format(myGuess))
        if myGuess == randomNum: # Winning routine when the guess matches the number.
           print("Congrats! You win!")
           totalWin += 1
           totalMatch += 1
           sleep(2)
           exitRoutine()
        if myGuess != randomNum and guesses == 10: # Losing routine when the guess does not match the number AND you reach guess number 10.
           print("Sorry, you lose. The number was {}." .format(randomNum))
           totalMatch += 1
           sleep(2)
           exitRoutine()
        
# Routine after a game is completed
def exitRoutine():
    while True:
        clear_output()
        print("Total matches: {}" .format(totalMatch))
        print("Total wins: {}" .format(totalWin))
        choice = input("Would you like to go again?\nY/N")
        if choice == "Y":
            clear_output()
            randomizer()
        if choice == "N":
            print("See you soon.")
            break
# -----------------------------------
# Menu code

def menu():
    while True:
        clear_output()
        print("Welcome to my program.")
        print("If you proceed, you have to guess a random number between 0 and 1000.")
        print("Can you outsmart a computer?")
        print("=====================\n1. Proceed\n2. Exit\n=====================")
        menuC = input("Enter your choice.")
        if menuC == "1":
            clear_output()
            randomizer()
        elif menuC == "2":
            print("See you later.")
            break
        else:
            print("Invalid choice.")
            input("Press enter to return.")
            clear_output()
            
if __name__ == "__main__": # Loops the menu
    menu()
        
Welcome to my program.
If you proceed, you have to guess a random number between 0 and 1000.
Can you outsmart a computer?
=====================
1. Proceed
2. Exit
=====================