+ 1

How come methods buy_pet() and del_pet() are not working?

https://code.sololearn.com/cnXCC5f7dKfn/?ref=app

14th Apr 2022, 1:13 PM
Lenoname
5 odpowiedzi
+ 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...
14th Apr 2022, 1:27 PM
Jayakrishna 🇮🇳
+ 2
In line 35 self.pet=pet, but thats not a list, so you cant append. Hope that helps
14th Apr 2022, 1:25 PM
Fu Foy
Fu Foy - avatar
+ 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
15th Apr 2022, 8:33 AM
Jayakrishna 🇮🇳
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
14th Apr 2022, 2:59 PM
Ion Kare
Ion Kare - avatar
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__?
15th Apr 2022, 12:37 AM
Lenoname