Posted By

ksaver on 02/18/11


Tagged

python random answers


Versions (?)

Pythonist.py


 / Published in: Python
 

URL: http://identi.ca/ksaver

A simple (and fun) random answer generator :-)

  1. #!/usr/bin/env python
  2. # Pythonist.py
  3. # ksaver, 27.03.2010
  4. # A simple (and nice) random answer generator :-)
  5.  
  6. import random
  7. import sys
  8.  
  9. progname = 'Pythonist'
  10. version = '0.2'
  11.  
  12. def randomize(num):
  13. return random.randint(0,num)
  14.  
  15. def get_answer():
  16. 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', '']
  17. return answers[randomize(len(answers) - 1)]
  18.  
  19. def say_bye():
  20. 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']
  21. return bye_says[randomize(len(bye_says) - 1)]
  22.  
  23. def main():
  24. print 'Welcome to %s %s' % (progname, version)
  25. print '-------------------------'
  26. print 'Give me a question and press [Enter].'
  27. print 'Write "bye", "quit" or "exit" to quit.'
  28. print
  29.  
  30. words_to_quit = ['bye', 'quit', 'exit']
  31. while True:
  32. question = ''
  33. while not question:
  34. question = raw_input('Give me your question:> ')
  35. if question.lower() in words_to_quit:
  36. print say_bye()
  37. print
  38. sys.exit(0)
  39. else:
  40. answer = get_answer()
  41. if answer:
  42. print answer
  43. else:
  44. print say_bye()
  45. print
  46. sys.exit(0)
  47.  
  48.  
  49. if __name__ == '__main__':
  50. main()

Report this snippet  

You need to login to post a comment.