Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import pi as PI
- class Point:
- """Klasa opisująca punkt na płaszczyźnie"""
- def __init__ (self,x1,y1):
- self.x = x1
- self.y = y1
- def __str__(self):
- return 'Location of the point in 2D is x={}, y={}'.format(self.x,self.y)
- class Figure(Point):
- def __init__ (self,x,y,
- colour = "red",
- name='figure',
- lineWidth=2,
- lineStyle='-'):
- super().__init__(x,y)
- self.colour = colour
- self.name = name
- self.lineWidth = lineWidth
- self.lineStyle = lineStyle
- def __str__(self):
- 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)
- def area(self):
- pass
- def perimeter(self):
- pass
- class Triangle(Figure):
- def __init__ (self,x,y,
- base,
- sideA,
- sideB,
- height,
- colour = "red",
- name = "triangle",
- lineWidth=2,
- lineStyle='-'):
- super().__init__(x,y,colour,name,lineWidth,lineStyle)
- self.base = base
- self.sideA = sideA
- self.sideB = sideB
- self.height = height
- def __str__(self):
- return "Base of a triangle = {}\nside a = {}\nside b = {}\nTriangle height = {}".format(self.base,self.sideA,self.sideB,self.height)
- def perimeter(self):
- return self.base + self.sideA + self.sideB
- def area(self):
- return 0.5*self.base*self.height
- class Rectangle(Figure):
- def __init__ (self,x,y,
- sideA,
- sideB,
- colour = "red",
- name = "rectangle",
- lineWidth=2,
- lineStyle='-'):
- super().__init__(x,y,colour,name,lineWidth,lineStyle)
- self.sideA = sideA
- self.sideB = sideB
- def __str__(self):
- return "Side A of the rectangle = {}\nSide B of the rectangle = {}".format(self.sideA,self.sideB)
- def perimeter(self):
- return 2*self.sideA + 2*self.sideB
- def area(self):
- return self.sideA*self.sideB
- class Circle(Figure):
- def __init__ (self,x,y,
- radius,
- colour = "red",
- name = "circle",
- lineWidth=2,
- lineStyle='-'):
- super().__init__(x,y,colour,name,lineWidth,lineStyle)
- self.radius = radius
- def __str__(self):
- return "Radius of circle = {}".format(self.radius)
- def perimeter(self):
- return 2*PI*self.radius
- def area(self):
- return self.radius**2*PI
- def main():
- print('pi = {}'.format(PI))
- pkt = Figure(3,4)
- print(30*'x',pkt.x,30*'x')
- print(pkt)
- print(30*'-')
- trian = Triangle(2,2,4,5,6,7)
- print(trian)
- print("Triangle area is equal: {} \nTriangle perimeter is equal = {}".format(trian.area(),trian.perimeter()))
- print(30*'-')
- rect = Rectangle(2,3,2,2)
- print(rect)
- print("Rectangle area is equal: {} \nRectangle perimemter is equal = {}".format(rect.area(),rect.perimeter()))
- print(30*'-')
- circ = Circle(2,3,12)
- print(circ)
- print("Circle area is equal: {} \nCircle perimeter is equal = {}".format(circ.area(),circ.perimeter()))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement