-1

I'm trying to make a quiz but I want to know how to make a random word generator.

The 4 words I need to be in this generator are: add, minus, divide and times.

question = random.randint(1,4)
if (question==1):
elif (question==2):
elif (question==3):
elif (question==4):

I'm using this for now but I would prefer for it to be words

falsetru
  • 357,413
  • 63
  • 732
  • 636
JD245
  • 61
  • 6

1 Answers1

0

Simply use random.choice. Using it, you don't need to index.

>>> import random
>>> random.choice(['add', 'minus', 'divide', 'times'])
'add'
>>> random.choice(['add', 'minus', 'divide', 'times'])
'times'
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • That should work. You could also make that a variable. Ex: choice = random.choice(['add', 'minus', 'divide', 'times']) then do print(choice) – Izzy Jan 30 '22 at 22:03