From f8df1e5fa0e345e23f75c924ca817811c5b53971 Mon Sep 17 00:00:00 2001 From: ehermakov Date: Mon, 28 Aug 2023 09:00:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B6=D0=B0?= =?UTF-8?q?=D1=8E=20=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=87=D0=B8=D0=B9=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0?= =?UTF-8?q?=D0=BD=D1=82=20=D0=94=D0=97=20=D0=BF=D0=BE=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B0=D0=BC=20(=D0=B1=D0=B5=D0=B7=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=20=D0=B2=20=D1=81=D1=82=D0=B0=D1=82=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../13082023 ДЗ по фигурам JSON/main.py | 15 +++++++-------- .../13082023 ДЗ по фигурам JSON/shape.py | 11 +++++++---- .../13082023 ДЗ по фигурам JSON/square.py | 1 - .../13082023 ДЗ по фигурам JSON/test.py | 0 4 files changed, 14 insertions(+), 13 deletions(-) delete mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/test.py 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