Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Rectangle:
- def __init__(self, width=0, height=0, name=''):
- self.width = width
- self.height = height
- self.name = name
- def calc_area(self):
- s = self.width * self.height
- return s
- def calc_perimeter(self):
- p = 2*(self.width + self.height)
- return p
- def print_info(self):
- print('Rectangle name: %s' % self.name)
- print('Width: %d\nHeight: %d' % (self.width, self.height))
- print('Area: %d\nPerimeter: %d' % (self.calc_area(), self.calc_perimeter()))
- r = Rectangle()
- r.width = 20
- r.print_info()
- r2 = Rectangle(10, 30, 'UKTC')
- r2.print_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement