-1
我想知道如何使用我的triplet詩歌程序打印出句子。 我的程序會隨機挑選一個要使用的名詞列表。Python:如何打印我的簡單詩歌
我的程序:
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()
例如,我可以有「牛走到鎮上但隨後被淹死。」用隨機器替換名詞/韻(牛,鎮,淹死)和動詞(走路)。
我會以某種方式使用random.randint嗎?
我只是基本上需要一個通用的打印語句,就像我使用隨機數發生器在隨機選擇名詞/押韻時顯示的示例一樣。
你可能想了解Python字符串格式化https://pyformat.info/ – lejlot
'nounsList = [nounList1,N ounList2]'這不是你連接列表的方式。 –
另外,不要用分號結束語句,換行符可以完成這項工作 – karlson