class Rectangle object def __init__ self width height self width width

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Rectangle(object):
def __init__(self, width, height):
self.width = width
self.height = height
@property
def perimeter(self):
return 2 * (self.width + self.height)
@property
def square(self):
return self.width * self.height
def set_width(self, value):
self.width = value
def set_height(self, value):
self.height = value
class Square(Rectangle):
def __init__(self, a):
super(Square, self).__init__(a, a)
if __name__ == '__main__':
rec = Rectangle(1, 2)
print 'rec perimeter:', rec.perimeter
print 'rec square:', rec.square
rec.set_width(3)
print 'rec perimeter:', rec.perimeter
print 'rec square:', rec.square
sq = Square(2)
print 'square perimeter:', sq.perimeter
print 'square sqare:', sq.square