Paid Apps Gone Free - PAGF (Beta)

Command Line Fun: Magic 8 Ball in Your Terminal


Need some advice or want to know an answer to a question that is bugging you for some time? You can use Magic 8 Ball for some guidance or fortune telling but need not to have a real one. You can do it in your terminal with a python script.

The Magic 8-Ball is a toy used for fortune-telling or seeking advice, manufactured by Mattel. It is a hollow plastic sphere that resembles a black 8 ball. To get an answer, you ask a question to the ball and turn it over. Check out a flash demo here

The python script for magic 8 ball is a very simple, straight forward script that is less than 15 lines of code. When you run the script, you are prompted to ask a question and it gives you any random answer that is in the code.

If you want some flashy stuff, you can grab the magic 8 ball screenlet from here

Instructions

1. Create a new text file with .py extension.
2. Copy and paste the following lines:

#!/usr/bin/env python
# Magic 8 ball program

import random
answers = ["As I see it, yes","It is certain","It is decidedly so","Most likely","Outlook good","Signs point to yes","Without a doubt","Yes","Yes definitely","You may rely on it","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"]
raw_input("What is your question?\n")
response = random.choice(answers)
print response + '\n'
while (True):
  raw_input("What is your question?\n")
  print random.choice(answers) + '\n'

3. Mark the file executable by right clicking the file and changing permissions in properties
4. Run the file in a terminal. Create a launcher if you wish.
5. You can change the answers easily by adding your own. Just add your answers between the brackets with quotes seperated by commas. For instance:  answers = ["Heck No", "You Kiddin' Me?"]

P.S. Check out some really funny questions people ask to magic 8 ball and their answers from here

[Many thanks to HoKaze and sisco311 @ Ubuntu Froums for the scripts]

0 comments:

Follow Us !!

Follow on TwitterFollow on FacebookGet PAGF Android App on Play StoreSubscribe via emailSubscribe to RSSFollow on Google Plus