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 ()
7
  • And where is something that you've done? I won't do your homework for you.
    – Aida Paul
    Nov 8, 2014 at 20:44
  • ill post an answer with what i have done so far and where im stuck. Nov 8, 2014 at 20:49
  • Don't post that as an answer, instead add that and explanation in your question.
    – Aida Paul
    Nov 8, 2014 at 20:49
  • i added what i have below everything. Nov 8, 2014 at 20:52
  • You forgot to explain why you are stuck, what seems to be the problem
    – Aida Paul
    Nov 8, 2014 at 20:53

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.