如何调试 python 多句生成器?

How do I debug a python multiple-sentence generator?

我自己编写了 Python 代码,如下所示:

import random

# nouns-----------------------------------------------------------------------------------------------------------------
nouns = 'noun1 noun2 noun3 noun4 noun5 noun6 noun7 noun8 noun9 noun10 noun11 noun12 noun13 noun14 noun15 noun16' .split()
def getRandomWord(nounList):
    wordIndex = random.randint(0, len(nounList) - 1)
    return nounList[wordIndex]
noun_var = getRandomWord(nouns)

# verbs-----------------------------------------------------------------------------------------------------------------
verbs = 'verb1 verb2 verb3 verb4 verb5 verb6 verb7 verb8 verb9 verb10 verb11 verb12 verb13 verb14 verb15 verb16' .split()
def getRandomWord(verbList):
    wordIndex = random.randint(0, len(verbList) - 1)
    return verbList[wordIndex]
verb_var = getRandomWord(verbs)

# infinitives-----------------------------------------------------------------------------------------------------------
infi = 'verb1 verb2 verb3 verb4 verb5 verb6 verb7 verb8 verb9 verb10 verb11 verb12 verb13 verb14 verb15 verb16' .split()
def getRandomWord(infiList):
    wordIndex = random.randint(0, len(infiList) - 1)
    return infiList[wordIndex]
infi_var = getRandomWord(infi)

# print strings
for i in range(1):
     print (noun_var, verb_var, infi_var)

但每当我想将 "Line 25, Char 16" 中的 1 更改为输入变量,让您能够选择想要的句子数量时,它只是一次又一次地重复相同的句子,而不是生成新的那些。有没有另一种方法可以用相同的原则制作一个 Python 的应用程序,或者有没有办法解决这个问题?

此代码在Python-3.x

如果您想在循环的每次迭代中显示不同的句子,则生成 一个新句子。现在你正在挑选 3 个随机单词,然后一遍又一遍地打印它们。

for i in range(int(input())):
     print (random.choice(nouns), random.choice(verbs), random.choice(infi))