-2

I'm creating a project where the person is supposed to respond and this randomizer is supposed to send a random response that would either be in the category of yes and no.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Sergio Ley
  • 85
  • 1
  • 14
  • 2
    Put the words in a list, then pick a random element of the list with `random.choice()`. – Barmar Oct 08 '19 at 01:10
  • @Barmar I did what you told me to do but then I got this error message: Traceback (most recent call last): File "project3.py", line 12, in from classref3 import Dog File "/Users/sergioley-languren/Documents/itt/independent_projects/classref3.py", line 3, in class Dog: File "/Users/sergioley-languren/Documents/itt/independent_projects/classref3.py", line 43, in Dog import random File "/Users/sergioley-languren/Documents/itt/independent_projects/random.py", line 3, in integers – Sergio Ley Oct 08 '19 at 01:26
  • @DawnChopin Don't name your _own_ file as random.py because that will hide the _true_ random module. – Gino Mempin Oct 08 '19 at 02:46
  • I reverted back to the original question. **If you have a new question, ask a new, separate question**. When you [completely changed the post](https://stackoverflow.com/revisions/58278961/2), the [existing answer](https://stackoverflow.com/a/58279062/2745495) and the comments do not all make sense anymore. Also, the original post was already closed and marked as a duplicate, making it unlikely someone else will notice it. Ask a new question if you have new problems. – Gino Mempin Oct 08 '19 at 02:50

1 Answers1

0

You can use random.choice to select a random element from a list of strings.

import random

allResponses = ['yes', 'no', 'maybe', 'so']
randomResponse = random.choice(responses)

See random.choice documentation