【发布时间】:2021-02-10 05:05:20
【问题描述】:
如何在多个打印命令之间随机选择?
比如……
我想随机选择这两个打印功能之一...
print ('The ball ', (random.choice (action_ball))
print ('The cat', (random.choice (action_cat))
然后参考这两个列表...
action_ball = ['rolled','bounced']
action_cat = ['purred','meowed']
随机生成这四个句子之一...
the ball rolled
the ball bounced
the cat purred
the cat meowed
我了解如何从一个列表中生成:
import random
action_ball = ['rolled','bounced']
print ('The ball ', (random.choice (action_ball))
在那之后,我迷路了。
【问题讨论】:
标签: python list random printing