我正在为一个课程作业创建一个随机句子生成器。我已经把所有的事情都搞清楚了,但是在句子模板中有一个地方,我们必须使用它,我需要先随机选择一个单词,然后在字符串中重复随机选择的单词。这个问题是随机出现的。当我需要立即使用任何被选中的单词时,请选择(地点)。我怎样才能抓到随机选择的同一个单词并再次使用?
import random
verb = ["dancing", "driving", "running"]
place = ["rain", "forest", "city"]
adjective = ["heavy", "long", "hard"]
count = 1
while count > 0:
generate = int(input('Press 1 to generate a new sentence or 2 to exit.\n'))
if generate == 1:
print('I like to go',random.choice(verb),'in the',random.choice(place),',but',place,'should not be too',random.choice(adjective),'.')
count = 1
else:
print('Ok, Goodbye!')
count = 0