So in my class I need to create a Surface Area and Volume calculator here are the instructions:
Write a Python program with a class for rectangular prisms and a subclass for cubes that will calculate volume and surface area of these geometric solids. Use the specs below to guide you through the process. When complete, zip the python file and upload the zipped file to the assignment dropbox.
Create a RectangularPrism class that has three instance variables for the three dimensions of a rectangular prism (length, width, and height).
Create a class method named volume that will return the volume of a rectangular prism. The formula for calculating the volume is to multiply the three dimensions.
Create another class method named surfaceArea that will return the surface area of a rectangular prism. The formula for calculating the surface area is to sum the areas of all six faces.
Create a Cube class that is a subclass of the RectangularPrism class. The Cube class only needs one argument since all three dimensions are the same length. Use the argument for each of the three dimensions.
Do not create new class methods for volume and surfaceArea in the Cube class because they are inherited from the RectangularPrism class.
Download and unzip the attached file. Either copy your code with the two classes to the top of this file or copy the code from this file to the bottom of your code. Add repr() methods to your classes so that when the program is run the output will look as shown below.
I tried my best following the instructions so here is my code:
class RectangularPrism(length, width, height):
indent preformatted text by 4 spaces
Formula1 = length * width * height
indent preformatted text by 4 spaces
Formula2 = length * length + width * width + height
indent preformatted text by 4 spaces
def volume():
indent preformatted text by 4 spaces``indent preformatted text by 4 spaces
return Formula1
indent preformatted text by 4 spaces
def surfaceArea():
indent preformatted text by 4 spaces``indent preformatted text by 4 spaces
return Formula2
class Cube(RectangularPrism):
indent preformatted text by 4 spaces
def init(self):
indent preformatted text by 4 spaces``indent preformatted text by 4 spaces
self.length = length
indent preformatted text by 4 spaces``indent preformatted text by 4 spaces
self.width = width
indent preformatted text by 4 spaces``indent preformatted text by 4 spaces
self.height = height
box1 = RectangularPrism(2, 3, 4)
print box1
print "Volume = " + str(box1.volume())
print "Suface Area = " + str(box1.surfaceArea())
box2 = Cube(2)
print box2
print "Volume = " + str(box2.volume())
print "Suface Area = " + str(box2.surfaceArea())
I am getting an error and I don’t know what I did wrong. What should I write to make this work?