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"))
2 Respostas
+ 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)
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).