Python random answering program

pythonrandom

I wrote this programm

#!/usr/bin/env python
"""
"""
import random
def CollectStrings():
   string_list = []
   while True:
      string = raw_input("What is your question: (enter to quit): ")
      if not string:
         return string_list
      string_list.append(string)

def ChooseStrings(how_many):
  string_list = CollectStrings()
  chosen = random.sample(string_list, how_many)
  chosen.sort()
  return ', '.join(chosen)

print ChooseStrings (3)

But I need to make this program randomly answer questions, like an 8ball.
How would I do that?

Best Answer

Add all answers to a list and than use random.choices to get a random answer:

import random

answers = [
    "The answer lies in your heart",
    "I do not know",
    "Almost certainly",
    "No",
    "Yes",
    "Why do you need to ask?",
    "Go away. I do not wish to answer at this time.",
    "Time will only tell",
]
print random.choice(answers) // Print random answer