Advertisement
vencinachev

OOP Python

Jan 10th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1.  
  2. class Rectangle:
  3.   def __init__(self, width=0, height=0, name=''):
  4.     self.width = width
  5.     self.height = height
  6.     self.name = name
  7.  
  8.   def calc_area(self):
  9.     s = self.width * self.height
  10.     return s
  11.  
  12.   def calc_perimeter(self):
  13.     p = 2*(self.width + self.height)
  14.     return p
  15.  
  16.   def print_info(self):
  17.     print('Rectangle name: %s' % self.name)
  18.     print('Width: %d\nHeight: %d' % (self.width, self.height))
  19.     print('Area: %d\nPerimeter: %d' % (self.calc_area(), self.calc_perimeter()))
  20.  
  21.  
  22. r = Rectangle()
  23. r.width = 20
  24. r.print_info()
  25. r2 = Rectangle(10, 30, 'UKTC')
  26. r2.print_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement