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 "Lokalizacja punktu: x={}, y={}".format(self.x,self.y)
- class Figure(Point):
- """Klasa opisująca figurę na płaszczyźnie o środku w punkcie Point"""
- listOfFigures = []
- def __init__ (self,x,y,
- colour = "czerwony",
- name="figura",
- lineWidth=2,
- lineStyle='-'):
- super().__init__(x,y)
- self.colour = colour
- self.name = name
- self.lineWidth = lineWidth
- self.lineStyle = lineStyle
- Figure.listOfFigures.append(self)
- def __str__(self):
- return 'Środek figury: x={}, y={}\nKolor figury = "{}"\nTyp figury = {}\nGrubość linii = {} \nStyl linii = "{}"'.format(self.x,self.y, self.colour,self.name,self.lineWidth,self.lineStyle)
- def area(self):
- """Metoda licząca pole figury"""
- pass
- def perimeter(self):
- """Metoda licząca obwód figury"""
- pass
- class Triangle(Figure):
- def __init__ (self,x,y,
- base,
- sideA,
- sideB,
- height,
- colour = "czerwony",
- name = "trójkąt",
- 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 "{} \nPole = {}, obwód = {}".format(super().__str__(),self.area(),self.perimeter())
- 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 = "czerwony",
- name = "prostokąt",
- lineWidth=2,
- lineStyle='-'):
- super().__init__(x,y,colour,name,lineWidth,lineStyle)
- self.sideA = sideA
- self.sideB = sideB
- def __str__(self):
- return "{} \nPole = {}, obwód = {}".format(super().__str__(),self.area(),self.perimeter())
- 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 = "czerwony",
- name = "koło",
- lineWidth=2,
- lineStyle='-'):
- super().__init__(x,y,colour,name,lineWidth,lineStyle)
- self.radius = radius
- def __str__(self):
- return "{} \nPole = {}, obwód = {}".format(super().__str__(),self.area(),self.perimeter())
- def perimeter(self):
- return 2*PI*self.radius
- def area(self):
- return self.radius**2*PI
- def main():
- pkt = Figure(3,4)
- trian = Triangle(2,2,4,5,6,7)
- rect = Rectangle(2,3,2,2)
- circ = Circle(2,3,12)
- listOfFigures = [pkt,trian,rect,circ]
- for figure in listOfFigures:
- print(figure)
- print(30*'-')
- print("Liczba figur: {}" .format(len(listOfFigures)))
- print("Lista figur: {}" .format(listOfFigures))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement