help plz ive been to atleast 10 different faqs and guides

Chad Netzer cnetzer at mail.arc.nasa.gov
Fri Nov 15 20:32:39 EST 2002


On Friday 15 November 2002 17:02, cmvb wrote:
> um yes id like to make a program so when you ask a question it responds
> with a preset set of random responses is this possible?

You mean like a Magic 8-Ball (tm)?


import random

# World's stupidest magic 8-ball simulator
def answer_question( question ):
    # Responses are probably copyright of Mattel
    responses = [ "Ask Again Later",
                  "Better Not Tell You Now",
                  "Concentrate and Ask Again",
                  "Don't Count on It",
                  "It Is Certain",
                  "Most Likely",
                  "My Reply is No",
                  "My Sources Say No",
                  "No",
                  "Outlook Good",
                  "Outlook Not So Good",
                  "Reply Hazy, Try Again",
                  "Signs Point to Yes",
                  "Yes",
                  "Yes, Definitely",
                  "You May Rely On It" ]

    i = int( random.randrange( len( responses ) ) )
    return responses[ i ]

def get_question():
    return raw_input( "What is your question?: " )

if __name__ == '__main__':
    print "Please ask 'Yes/No' questions..."
    while 1:
        print answer_question( get_question() )
        print


-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list