In [ ]:
from random import randint
from IPython.display import clear_output
from time import sleep
# -------------------------------------------------------------
# 8-Ball program
def m8Ball():
        clear_output()
        sleepTimer = randint(3,6) # Randomly selects an integer between 3 and 6
        question = input("Ask the oracle a question.")
        answersLST = [ "As I see it, yes.",
            "Ask again later.",
            "Better not tell you now.",
            "Cannot predict now.",
            "Concentrate and ask again.",
            "Don’t count on it.",
            "It is certain.",
            "It is decidedly so.",
            "Most likely.",
            "My reply is no.",
            "My sources say no.",
            "Outlook not so good.",
            "Outlook good.",
            "Reply hazy, try again.",
            "Signs point to yes.",
            "Very doubtful.",
            "Without a doubt.",
            "Yes.",
            "Yes",
            "definitely.",
            "You may rely on it."
             ] # List of possible answers by the 8-Ball
        answer = randint(0,19) # Selects a random integer between 0 and 19
        response = answersLST[answer] # Randomly selects a response using whatever integer was generated by the 'answer' variable
    
        if question == "":
         print("The answer to your secret question is..")
         sleep(sleepTimer)
            
         print(response) # If the question is left blank, the 8-Ball interprets it as a secret question, and prints a response
        
        else:
         print("I am formulating your answer..")
         sleep(sleepTimer)

         print(response) # Prints a response in any other condition
            
        retry = input("Would you like to ask again? Y/N") # Loops the Magic 8-Ball function when Y is entered, and returns to the menu if N is entered
        if retry == "Y":
         m8Ball()
         clear_output()
            
        elif retry == "N":
           print("Farewell for now!")
        sleep(3)
        clear_output()
# ------------------------------------------------------------- 
# Menu that allows user to ask the 8-Ball a question or exit
def menu():
    while True:
        print("Welcome to the Magic 8-Ball.")
        print("What would you like to do today?")
        print("----------------------------------")
        print("1. Ask a question")
        print("2. Exit")
        print("----------------------------------")
        menuChoice = input("Enter 1 or 2 here")

        if menuChoice == "1": # Runs the Magic 8-Ball function
            m8Ball()
        elif menuChoice == "2": # Breaks out of the 'while True' loop
            print("See you later. :-)")
            break
        else: # Returns user to menu if any answer that isn't 1 or 2 is entered
            print("Invalid choice.")
            input("Press enter to return to the previous screen.")
            clear_output()
if __name__ == "__main__": # Loops the menu
    menu()
The answer to your secret question is..
Don’t count on it.