+ 1
How come methods buy_pet() and del_pet() are not working?
5 Answers
+ 4
Your 'pet' is not a list to append value or to delete. Owner, pet are object which don't have append or pop methods implemented...
+ 2
In line 35 self.pet=pet, but thats not a list, so you cant append. Hope that helps
+ 1
class owpet :
def buy_pet(self, pet) :
self.pet.append(pet)
def del_pet(self, pet) :
self.pet.remove(pet)
pet = []
def __init__ (self, owner, pet) :
self.owner = owner
self.pet.append(pet)
#Try this Lenoname
0
https://code.sololearn.com/cvryHJs3qEAO/?ref=app
You cannot pop a name you can only pop last element
Or reverse
If u want to delete you would need to use something else
you functions should be after init functions not before
i would rewite the code
in order
Owner first
Pets second
Own pets third
if you want to keep track of all the pets add and empty list after the class but before the init like how i did with the owpets
something like this
https://code.sololearn.com/cRWKPtm1ZOdh
0
Ion Kare Owpet class was made to assign pets to an owner, does your version have a solution for multiple pets? I mean an owner having more than 1 pet. Also why cant i have functions/methods before __init__?