Need help in making this run correctly. class Box: def __init__(self,weight,leng
ID: 3535248 • Letter: N
Question
Need help in making this run correctly.
class Box:
def __init__(self,weight,length,width,height):
self.weight = weight
self.length = length
self.width = width
self.height = height
def getVolume(self,volume):
#volume = volume
volume = self.length * self.width * self.height
return volume
def getMassDensity(self,volume):
return self.weight/volume
def main():
box1 = Box(100,10,2,10)
print("For box # 1, the volume is %f and mass density is %f" %( box1.getVolume(), box1.getMassDensity() ) )
box2 = Box(200,50,5,40)
print("For box # 2, the volume is %f and mass density is %f" %( box2.getVolume(), box2.getMassDensity() ) )
Explanation / Answer
the problume you have is in your getMassDensity routine you can't just use volume like that
so change it to
def getMassDensity(self):
return self.weight/self.getVolume()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.