DragonZeith
DragonZeith

Reputation: 71

How do I debug a python multiple-sentence generator?

I made my own Python code like this:

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)

But whenever I wanted to change the 1 in "Line 25, Char 16" into an input variable letting you be able to make the choice of how many sentences wanted, it just repeats the same sentence again and again instead of generating new ones. Is there another way to make an app with Python with the same principles or is there a way to fix this?

This code is in Python-3.x

Upvotes: 0

Views: 208

Answers (1)

Aran-Fey
Aran-Fey

Reputation: 43266

If you want to display a different sentence in each iteration of your loop, then generate a new sentence. Right now you're picking 3 random words, and then printing them over and over again.

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

Upvotes: 1

Related Questions