So here it is, a simple magic 8 ball program in python. By using this oracle you agree that your doing so at your own risk.
is neither affiliated with this site, nor with authors of this site. (Press 'Enter' for answer and 'q' to exit) The 'Magic Eight Ball' trademark and various 8-Ball answers are used without permission of Mattel Inc. Output Press 'Enter' for answer and 'q' to exit) The answer is chosen from the list randomly and printed using print().Īfter printing the answer we make a recursive call to magic8ball() so that we can offer the user a chance to ask another question or quit. We use random.choice(Eightball_answers) for this. If the user pressed any other key then we choose a random answer from our list of answers and display it. If it was quit then we display an exiting message and exit the program. Next we use an if…else statement to check if the input was ‘quit’ or not. NOTE: You can add or remove these answers. They include “It is certain”, “Outlook good”, “You may rely on it”, “Ask again later”, “Concentrate and ask again”, “Reply hazy, try again”, “My reply is no”, “My sources say no”. We have also created a list of answers stored in Eightball_answers. We are using \n to print the sentence on a new line. This input is read using input() and stored in the variable response. They then press ‘any key’to get the answer or ‘quit’to exit the program. Inside this function we start by Asking the user to think of a question to which he or she wants answered. This is our function which will generate and answer and display it to the user. We define a function called magic8ball(). Random module is used to find a random answer from the list of answers. We start by importing a module whose functions we will be using in the program. Print(random.choice(Eightball_answers), "\n") Response = input("(Press 'any key' for answer and 'quit' to exit)\nWhat is your question?\n") We will be asking the user to think of the question they wanna ask the Magic 8 Ball and then we will randomly choose an answer from a pre-defined list of answers.
The obvious solution to this is to add a built-in clairvoyant feature to the Ask a Question page. So many interesting questions get asked on Stack Overflow and then immediately closed (or worse yet, closed and re-opened for days on end) because they're subjective, argumentative, and fundamentally unanswerable due to our lack of omniscience: without the ability to see into the future and/or know the secret motivations of companies and their developers, we are left to make wildly varying (un)informed guesses.