Python Inheritance
create program to calculate volume of small box and big box and find the capacity =big box/ small box
program
class Box:
def __init__(self,length,width,height):
self.length=length
self.width=width
self.height=height
def getvolume(self):
vol=self.length*self.width*self.height
return vol
class BigBox(Box):
def __init__(self,length,width,height):
Box.__init__(self,length,width,height)
def getcapicity(self,sbox):
self.sbox=sbox
capacity=Box.getvolume(self)/sbox.getvolume()
return capicity
s=Box(2,1,1)
b=BigBox(4,4,4)
s1=b.getcapacity(s)
print(s1)
def __init__(self,length,width,height):
self.length=length
self.width=width
self.height=height
def getvolume(self):
vol=self.length*self.width*self.height
return vol
class BigBox(Box):
def __init__(self,length,width,height):
Box.__init__(self,length,width,height)
def getcapicity(self,sbox):
self.sbox=sbox
capacity=Box.getvolume(self)/sbox.getvolume()
return capicity
s=Box(2,1,1)
b=BigBox(4,4,4)
s1=b.getcapacity(s)
print(s1)
Comments
Post a Comment