My problem definition is as follows:
Creating a class name called "Kangaroo".
1] An __init__ method that initializes an attribute named pouch_contents to an empty list.
2]A method named by creating put_in_pouch that takes an object of any type and adds it to pouch_contents.
The following is the code I have written:
class Kangaroo: def __init__(self,pouch=,pouch_contents=10): self.pouch.append(pouch_contents) print self.pouch def __add__(self,other): if isinstance(other,Kangaroo): return self.put_in_pouch(other) else: return False def __print__(self): print '%d'% (self.pouch) def put_in_pouch(self,other): temp=Kangaroo() temp.pouch=self.pouch+other.pouch return temp kanga=Kangaroo() roo=Kangaroo() print kanga + roo
I am testing the code by creating 2 Kangaroo class objects. But for the surprising fact that the pouch_contents don't get added to the specific Kangaroo object. It adds to a normal list. But it's not what I want. I want to add the pouch_contents for the specific object as it I ultimately would like to add contents off 2 different objects.