我想知道如何用我的三连体诗程序打印出句子。 我的程序随机选择要使用的名词列表。在
我的计划:
import random
def nouns():
nounPersons = ["cow","crowd","hound","clown"];
nounPlace = ["town","pound","battleground","playground"];
rhymes = ["crowned","round","gowned","found","drowned"];
nounPersons2 = ["dog","frog","hog"];
nounPlace2 = ["fog","Prague","smog"];
rhymes2 = ["log","eggnog","hotdog"];
nounList1 = [nounPersons,nounPlace,rhymes]
nounList2 = [nounPersons2,nounPlace2,rhymes2]
nounsList = [nounList1, nounList2]
randomPick = random.choice(nounsList)
return(randomPick)
verbs = ["walked","ran","rolled","biked","crawled"];
nouns()
例如,我可以“牛走到镇上。然后用我的随机化器替换名词/押韵(cow,town,sounded)和动词(walked)。在
我会用吗随机.randint在某种程度上?在
我基本上只需要一个通用的打印语句,就像我用随机数发生器在名词/韵脚之间随机选择的例子一样。在
像往常一样(对我来说),可能还有一种更像Python的方法,但为了让你的工作发挥作用,我做了三件事:
将对nomens()函数的调用分配给“choosed\u list”变量。这样就可以使用返回的“randomPick”。
内置一个选择步骤,从“choosed”列表和动词列表中获取单个单词
添加了带格式的final print语句以将单词组合成一个句子
代码:
相关问题 更多 >
编程相关推荐