×
☰ Sebsnetwork

Magic 8 ball - Python - 3KB

                
                    #Tested versions
#3.7.9
#3.11.3

#Imports
import random
import os
import time
#===============
#Configurations

#Add delay betweeen asking question and getting responce ( TRUE / FALSE )
responce_delay = False

#===============

#Magic 8 Ball responces.
responces = ["It is certain.", "It is decidedly so.", "Without a doubt.","Yes definitely.","You may rely on it.", "As I see it, yes.", "Most likely.", "Outlook good.", "Yes.","Signs point to yes.","Reply hazy, try again", "Ask again later.","Better not tell you now", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "My reply is no.","My sources say no.", "Outlook not so good","Very doubtful."]

#Clearing the console.
def clear_conole():
    print("\n"*100)
    print("\n"*100)
    os.system("cls")

def awaiting_responce():
    clear_conole()
    number = 0
    waiting = "."
    while number != 5:
        clear_conole()
        number += 1
        if waiting == ".":
            print(waiting)
            waiting = ".."
        elif waiting == "..":
            print(waiting)
            waiting = "..."
        elif waiting == "...":
            print(waiting)
            waiting = "."
        time.sleep(0.5)
    
    

clear_conole()
#Making a loop till user doesn't want more answers
while True:
    while True:
        try:
            user_input = input("Please enter your question:\n - ")
            if user_input == "":
                print("ERROR - Input cannot be blank: Please enter a responce")
            else:
                break
        except:
            
            print("Something has gone wrong!")
    if responce_delay == True:
        awaiting_responce()
    clear_conole()
    print(f"Question: {user_input}\nAnswer: {random.choice(responces)}")
    while True:
        try:
            user_input = int(input("Do you want to ask again?\n1) Yes\n2) No\n - "))
            if user_input == 1 or user_input == 2:
                break
            else:
                print("ERROR - Please only enter 1 or 2")   
        except:
            print("ERROR - Please only enter 1 or 2")
    if user_input == 2:
        break
    clear_conole()
print("Goodbye")