/ Published in: Python
A simple (and fun) random answer generator :-)
Expand |
Embed | Plain Text
#!/usr/bin/env python # Pythonist.py # ksaver, 27.03.2010 # A simple (and nice) random answer generator :-) import random import sys progname = 'Pythonist' version = '0.2' def randomize(num): return random.randint(0,num) def get_answer(): answers = ['Yes', 'Yep!', 'No', 'Nope!', 'May be', 'Perhaps, perhaps, perhaps...', 'May be, some day', 'Are you insane?', 'Have it for sure!', 'Yes, sure', 'What kind of question is that?', 'I can\'t answer that!', 'Yes, it\'s a fact!', 'Sorry, you don\'t must to know that', 'Absolutelly yes', 'You are setting me angry', 'No, that is wrong', 'Yes, rigth', 'Yes, but not today', 'Sshh... be quiet', ''] return answers[randomize(len(answers) - 1)] def say_bye(): bye_says = ['Good bye', 'Ok, bye', 'A pleassure to chat with you', 'Bye, bye', 'See you later aligator! :-)', 'Sorry, I have to go now', 'Go hell.', 'Fly a kite'] return bye_says[randomize(len(bye_says) - 1)] def main(): print 'Welcome to %s %s' % (progname, version) print '-------------------------' print 'Give me a question and press [Enter].' print 'Write "bye", "quit" or "exit" to quit.' words_to_quit = ['bye', 'quit', 'exit'] while True: question = '' while not question: question = raw_input('Give me your question:> ') if question.lower() in words_to_quit: print say_bye() sys.exit(0) else: answer = get_answer() if answer: print answer else: print say_bye() sys.exit(0) if __name__ == '__main__': main()
You need to login to post a comment.
