diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/main.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/main.py index 1e9f0bf..62592d9 100755 --- a/HNS/Excercises/13082023 ДЗ по фигурам JSON/main.py +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/main.py @@ -1,18 +1,17 @@ import json from shape import Shape - def json_to_python(): with open("shapes.json") as lines: data = json.load(lines) - for shape in data["shapes"]: - print("Type:", shape["type"]) - print("Color:", shape["color"]) + for i in data["shapes"]: print() - sh1 = shape.create_shape(shape) - print(sh1.perimetr()) - print(sh1.area()) - return True + print("Type:", i["type"]) + print("Color:", i["color"]) + sh1 = Shape.create_shape(i) + print(sh1) + + return "Программа завершена" print(json_to_python()) diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py index 6c99365..cb70176 100644 --- a/HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py @@ -17,12 +17,15 @@ class Shape(ABC): def create_shape(json): if "type" in json: shape_type = json["type"] - if shape_type == "circle": - return Circle(json("radius")) + return json["radius"] elif shape_type == "square": - return Square(json("side")) + return json["side"] elif shape_type == "rectangle": - return Rectangle(json["width"], json["height"]) + return json["width"], json["height"] else: raise TypeError(f'Неизвестная фигура {shape_type}') + + + +print() \ No newline at end of file diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/square.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/square.py index 54da53b..b39b3d4 100644 --- a/HNS/Excercises/13082023 ДЗ по фигурам JSON/square.py +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/square.py @@ -4,7 +4,6 @@ from shape import Shape class Square(Shape): def __init__(self, side): self.side = side - self.color = color def area(self): return self.side ** 2 diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/test.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/test.py deleted file mode 100644 index e69de29..0000000