Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote