help plz ive been to atleast 10 different faqs and guides

John Hunter jdhunter at nitace.bsd.uchicago.edu
Fri Nov 15 20:23:18 EST 2002


>>>>> "cmvb" == cmvb  <cmvb at optonline.net> writes:

    cmvb> um yes id like to make a program so when you ask a question
    cmvb> it responds with a preset set of random responses is this
    cmvb> possible?

Yep.  I just hope you aren't trying to write one of those spam bots
trying to imitate a person while advertising in a chat room.

import random
answers = ['Are you crazy?',
           'Exactly.',
           'Are you through yet?',
           'Yeah, I remember when I had my first beer',
           ]

# ind is a random index into the answers list
ind = random.randrange(len(answers))
print answers[ind]

This is sampling with replacement.  If you want sampling without
replacement, there are other options....

Here is a link to the library documentation for the random module
http://www.python.org/doc/lib/module-random.html


Cheers,
John Hunter


        




More information about the Python-list mailing list