0

Please help with completing this. I am stuck and cant seem to get it. Below this is what i was given and below the code is what the output needs to be.

def main():
print ("Rectangle a:")
a = Rectangle(5, 7)
print ("area:      {}".format(a.area))
print ("perimeter: {}".format(a.perimeter))

print ("")
print ("Rectangle b:")
b = Rectangle()
b.width = 10
b.height = 20
print (b.getStats())

Expected Output

When the Rectangle class has been properly created, the output should look like the following:

Rectangle a:
area:      35
perimeter: 24
Rectangle b:
width:     10
height:    20
area:      200
perimeter: 60

this is what i have done from what i know. I missed the lecture for a family emergency and dont know how to finish it.

class Rectangle: 
    def __init__ (self, H=0, W=0): 
        self.width = W 
        self.height = H 

@property 
    def area (self): 
        return self.width * self.height 

def main(): 
    print ("Rectangle a:") 
    a = Rectangle (5, 7) 
    #print ("area: {}".format(a.area)) 
    #print ("perimeter: {}".format(a.perimeter)) 
    print ("") 
    print ("Rectangle b:") 
    b = Rectangle() 
    b.width = 10 
    b.height = 20 
    #print (b.area) 
    #print (b.getStats()) 

main ()

1 Answers1

1

First and foremost, you should roll a newspaper and whack the teacher on the nose for proposing the use of function named main(). Python already comes with __main__ which you are welcome to use.

As for your ongoing issue, I took a liberty of reworking your code a bit, and you should be able to follow its lead on the road to success.

class Rectangle: 
    def __init__ (self, H=0, W=0): 
        self.width = W 
        self.height = H 

    @property 
    def area (self): 
            return self.width * self.height 

if __name__ == "__main__": 
    a = Rectangle (5, 7) 
    print ("Rectangle a.w: %s a.h: %s" % (a.width, a.height)) 
    b = Rectangle() 
    b.width = 10 
    b.height = 20 
    print ("Rectangle b.w: %s b.h: %s" % (b.width, b.height)) 
Tymoteusz Paul
  • 2,732
  • 17
  • 20