Missing atribute python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Missing atribute python

When i run the code it says type object 'insulter' has no attribute 'insult' i do not get why code: import random class insulter: def __init__(self,name): randominsult = random.choice(insultlist) insultlist = ['You stink', 'You suck', 'Even a eye doctor would not look at you'] insult = name + randominsult print(insulter.insult("Adolf hitler"))

11th Mar 2018, 7:02 PM
Raoul Scholtens
Raoul Scholtens - avatar
2 Answers
+ 5
Try this... import random class insulter: def __init__(self,name): insultlist = ['You stink', 'You suck', 'Even a eye doctor would not look at you'] randominsult = random.choice(insultlist) self.insult = name + ", " + randominsult print(insulter("Adolf hitler").insult)
11th Mar 2018, 7:29 PM
John Wells
John Wells - avatar
0
It says that it has no attribute named insult because it doesn't. You don't define it all you define is the __init__ method (which has an error too the insultlist initialization should be before you pick a random element).
11th Mar 2018, 7:09 PM
Marcus Søndergaard
Marcus Søndergaard - avatar