mardi 27 octobre 2020

How can I randomly choose between multiple print commands?

How can I randomly choose between multiple print commands?

For instance...

I want to randomly choose one of these two print functions...

print ('The ball ', (random.choice (action_ball))
print ('The cat', (random.choice (action_cat))

then reference these two lists...

action_ball = ['rolled','bounced']
action_cat = ['purred','meowed']

to randomly generate one of these four sentences...

the ball rolled
the ball bounced
the cat purred
the cat meowed

I understand how to generate from one list:

import random
action_ball = ['rolled','bounced']
print ('The ball ', (random.choice (action_ball))

After that, I'm lost.




Aucun commentaire:

Enregistrer un commentaire