Brand Mellor Brand Mellor - 1 year ago 89
Python Question

Insult Generator Gone Wrong

I am making an insult generator for class that uses one word from three lists within a tuple named

. For some reason, while my
function generates an insult, my
function generates
"Thou A l l!"

Does anybody have any idea what is going on?

Here's the relevant code

def generateInsult(word='allWords'):
insult = "Thou " + random.choice(word[0]) + " " + random.choice(word[1]) + " " + random.choice(word[2]) + "!"
return insult

def generateInsults(word='allWords'):
insults = list()
for i in range(100):
return insults

Answer Source

I understand that you have a 3-tuple of lists called allWords. You should remove the quotes around the default argument, ie change the following lines:

def generateInsult(word=allWords):

def generateInsults(word=allWords):