Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | None | 0 0
  1. from math import pi as PI
  2.  
  3. class Point:
  4.     """Klasa opisująca punkt na płaszczyźnie"""
  5.     def __init__ (self,x1,y1):
  6.       self.x = x1
  7.       self.y = y1
  8.  
  9.     def __str__(self):
  10.       return 'Location of the point in 2D is x={}, y={}'.format(self.x,self.y)
  11.  
  12.  
  13. class Figure(Point):
  14.   def __init__ (self,x,y,
  15.               colour = "red",
  16.               name='figure',
  17.               lineWidth=2,
  18.               lineStyle='-'):
  19.     super().__init__(x,y)
  20.     self.colour = colour
  21.     self.name = name
  22.     self.lineWidth = lineWidth
  23.     self.lineStyle = lineStyle
  24.  
  25.   def __str__(self):
  26.     return 'center of the figure x={}, y={}\ncolour of figure = "{}"\ntype of figure = {}\nline width = {} \nstyle of line = "{}"'.format(self.x,self.y, self.colour,self.name,self.lineWidth,self.lineStyle)
  27.  
  28.   def area(self):
  29.     pass
  30.  
  31.   def perimeter(self):
  32.     pass
  33.  
  34.  
  35. class Triangle(Figure):
  36.   def __init__ (self,x,y,
  37.         base,
  38.         sideA,
  39.         sideB,
  40.         height,
  41.         colour = "red",
  42.         name = "triangle",
  43.         lineWidth=2,
  44.         lineStyle='-'):
  45.          super().__init__(x,y,colour,name,lineWidth,lineStyle)
  46.          self.base = base
  47.          self.sideA = sideA
  48.          self.sideB = sideB
  49.          self.height = height
  50.  
  51.   def __str__(self):
  52.     return "Base of a triangle = {}\nside a = {}\nside b = {}\nTriangle height = {}".format(self.base,self.sideA,self.sideB,self.height)
  53.  
  54.   def perimeter(self):
  55.     return self.base + self.sideA + self.sideB
  56.  
  57.   def area(self):
  58.     return 0.5*self.base*self.height
  59.  
  60.  
  61. class Rectangle(Figure):
  62.   def __init__ (self,x,y,
  63.       sideA,
  64.       sideB,
  65.       colour = "red",
  66.       name = "rectangle",
  67.       lineWidth=2,
  68.       lineStyle='-'):
  69.         super().__init__(x,y,colour,name,lineWidth,lineStyle)
  70.         self.sideA = sideA
  71.         self.sideB = sideB
  72.  
  73.   def __str__(self):
  74.     return "Side A of the rectangle = {}\nSide B of the rectangle = {}".format(self.sideA,self.sideB)
  75.  
  76.   def perimeter(self):
  77.     return 2*self.sideA + 2*self.sideB
  78.  
  79.   def area(self):
  80.     return self.sideA*self.sideB
  81.  
  82. class Circle(Figure):
  83.   def __init__ (self,x,y,
  84.     radius,
  85.     colour = "red",
  86.     name = "circle",
  87.     lineWidth=2,
  88.     lineStyle='-'):
  89.       super().__init__(x,y,colour,name,lineWidth,lineStyle)
  90.       self.radius = radius
  91.  
  92.   def __str__(self):
  93.     return "Radius of circle = {}".format(self.radius)
  94.  
  95.   def perimeter(self):
  96.     return 2*PI*self.radius
  97.  
  98.   def area(self):
  99.     return self.radius**2*PI
  100.  
  101.  
  102. def main():
  103.   print('pi = {}'.format(PI))
  104.   pkt = Figure(3,4)
  105.   print(30*'x',pkt.x,30*'x')
  106.   print(pkt)
  107.  
  108.   print(30*'-')
  109.  
  110.   trian = Triangle(2,2,4,5,6,7)
  111.   print(trian)
  112.   print("Triangle area is equal: {} \nTriangle perimeter is equal = {}".format(trian.area(),trian.perimeter()))
  113.  
  114.   print(30*'-')
  115.  
  116.   rect = Rectangle(2,3,2,2)
  117.   print(rect)
  118.   print("Rectangle area is equal: {} \nRectangle perimemter is equal = {}".format(rect.area(),rect.perimeter()))
  119.  
  120.   print(30*'-')
  121.  
  122.   circ = Circle(2,3,12)
  123.   print(circ)
  124.   print("Circle area is equal: {} \nCircle perimeter is equal = {}".format(circ.area(),circ.perimeter()))
  125.  
  126. if __name__ == '__main__':
  127.   main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement