Brand Mellor Brand Mellor - 2 years ago 118
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):
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download