Hi All,
I am new to programming & trying to learn python.
I have created Product class(as Parent) & Inventory (as child) class. How can i use attributes declared in product class in inventory class. In the below example i want to use Product attribute 'pcost' in inventory class.
In Cost function i want to do pcost * pnbr.
Please help.
class Product():
def __init__(self,pname,pid,pcost):
self.pname = pname
self.pid=pid
self.pcost=pcost
class Inventory(Product):
def __init__(self,pnbr,products):
self.pnbr=pnbr
def cost(self):
self.cost=self.pcost*self.pnbr
Pro1=Product('Cookie','01',5)
Pro2=Product('Milk','02',3)
I am new to programming & trying to learn python.
I have created Product class(as Parent) & Inventory (as child) class. How can i use attributes declared in product class in inventory class. In the below example i want to use Product attribute 'pcost' in inventory class.
In Cost function i want to do pcost * pnbr.
Please help.
class Product():
def __init__(self,pname,pid,pcost):
self.pname = pname
self.pid=pid
self.pcost=pcost
class Inventory(Product):
def __init__(self,pnbr,products):
self.pnbr=pnbr
def cost(self):
self.cost=self.pcost*self.pnbr
Pro1=Product('Cookie','01',5)
Pro2=Product('Milk','02',3)