Welcome to Code Sharer, a code gallery for creating, saving and sharing all kinds of code snippets.

Python — Magic 8 ball

Posted On: Wednesday, December 14, 2016 at 8:04 AM

Only 8 examples are programmed in to this code. However it is very simple to add more.
# Import the modules
import sys
import random

ans = True

while ans:
question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ")

answers = random.randint(1,8)

if question == "":

elif answers == 1:
print "It is certain"

elif answers == 2:
print "Outlook good"

elif answers == 3:
print "You may rely on it"

elif answers == 4:
print "Ask again later"

elif answers == 5:
print "Concentrate and ask again"

elif answers == 6:
print "Reply hazy, try again"

elif answers == 7:
print "My reply is no"

elif answers == 8:
print "My sources say no"

Ryan Bradley-Evans (Admin)

Joined on
Contributed 16 Snips

Get Social and Share