From f42cb4fedada9ea1ba08883e91a5f4688f3176b1 Mon Sep 17 00:00:00 2001 From: ehermakov Date: Sun, 27 Aug 2023 15:12:28 +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=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D1=81=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B=D0=BC=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes HNS/.DS_Store | Bin 6148 -> 6148 bytes HNS/Excercises/.DS_Store | Bin 8196 -> 6148 bytes .../.idea/.gitignore | 3 ++ .../.idea/13082023 ДЗ по фигурам JSON.iml | 8 +++++ .../.idea/inspectionProfiles/profiles_settings.xml | 6 ++++ .../.idea/misc.xml | 4 +++ .../.idea/modules.xml | 8 +++++ .../13082023 ДЗ по фигурам JSON/.idea/vcs.xml | 6 ++++ .../13082023 ДЗ по фигурам JSON/Shape.py | 7 ----- .../{Circle.py => circle.py} | 5 ++-- .../13082023 ДЗ по фигурам JSON/main.py | 4 +++ .../{Rectangle.py => rectangle.py} | 9 ++++-- .../13082023 ДЗ по фигурам JSON/shape.py | 28 ++++++++++++++++++ .../{Square.py => square.py} | 4 +-- 15 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/.gitignore create mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/13082023 ДЗ по фигурам JSON.iml create mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/misc.xml create mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/modules.xml create mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/vcs.xml delete mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/Shape.py rename HNS/Excercises/13082023 ДЗ по фигурам JSON/{Circle.py => circle.py} (68%) rename HNS/Excercises/13082023 ДЗ по фигурам JSON/{Rectangle.py => rectangle.py} (67%) create mode 100644 HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py rename HNS/Excercises/13082023 ДЗ по фигурам JSON/{Square.py => square.py} (75%) diff --git a/.DS_Store b/.DS_Store index 488c2846df359abcb33bc7dfe1842a6c259e7d2d..4b6330a9d200af808af5d91b75e9410bc964ae08 100644 GIT binary patch delta 14 VcmZoMXffFEl8Mn|^D8DPQ2;5-1qT2C delta 14 VcmZoMXffFEl8Mo9^D8DPQ2;5r1q1*9 diff --git a/HNS/.DS_Store b/HNS/.DS_Store index c53f21035e80a6fcdfd3bd64ac801e66fb70e2e2..7391456f1e30fd988a35e744ce894c1517e2b582 100644 GIT binary patch delta 14 VcmZoMXffDupNY|A^8+RoQ2;4k1pNR2 delta 14 VcmZoMXffDupNY|M^8+RoQ2;4S1o{8~ diff --git a/HNS/Excercises/.DS_Store b/HNS/Excercises/.DS_Store index 7e583a9ecaf1837b686b5b9e4367241942369baf..5794bfea7e0592c33b2ce14383f2f80fe57a57c6 100644 GIT binary patch delta 105 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jG)aU^g=(+h!htMyAb-B2|ow q**Q1_nSn}xK!6)axPnw~Ed0(qnP0{eq?dsSVh+e?hRyLjbC>~WbPv1$ delta 261 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$gweCH}hr%jz7$c**Q2SHn1>q zZ02EUWU^IfFk~=dFkr9%lST~23<@l=ECwtV%xo-9EEYhX5shq z6t!cqp8Sbr@?=+bHwsNrVN=}P%T~p>v7v`akQwM~Aduh&60RU0Y!>AB&ODi4#B;Jg c4+jS$#B&Uj<9Vh}?qxHde2Cq3V?!qs00fFFAOHXW diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/.gitignore b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/13082023 ДЗ по фигурам JSON.iml b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/13082023 ДЗ по фигурам JSON.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/13082023 ДЗ по фигурам JSON.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/inspectionProfiles/profiles_settings.xml b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/misc.xml b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/misc.xml new file mode 100644 index 0000000..a971a2c --- /dev/null +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/modules.xml b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/modules.xml new file mode 100644 index 0000000..db2ac21 --- /dev/null +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/vcs.xml b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/Shape.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/Shape.py deleted file mode 100644 index 8f49981..0000000 --- a/HNS/Excercises/13082023 ДЗ по фигурам JSON/Shape.py +++ /dev/null @@ -1,7 +0,0 @@ - -class Shape: - def area(self): - return NotImplementedError("Необходимо переопределить метод area в дочернем классе") - - def perimetr(self): - return NotImplementedError("Необходимо переопределить метод perimetr в дочернем классе") diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/Circle.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/circle.py similarity index 68% rename from HNS/Excercises/13082023 ДЗ по фигурам JSON/Circle.py rename to HNS/Excercises/13082023 ДЗ по фигурам JSON/circle.py index 9f938c4..b89c84f 100644 --- a/HNS/Excercises/13082023 ДЗ по фигурам JSON/Circle.py +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/circle.py @@ -1,11 +1,10 @@ import math -from Shape import Shape +from shape import Shape class Circle(Shape): - def __int__(self, radius, color): + def __init__(self, radius): self.radius = radius - self.color = color def area(self): return math.pi * (self.radius ** 2) diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/main.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/main.py index 8169392..1e9f0bf 100755 --- a/HNS/Excercises/13082023 ДЗ по фигурам JSON/main.py +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/main.py @@ -1,4 +1,5 @@ import json +from shape import Shape def json_to_python(): @@ -8,6 +9,9 @@ def json_to_python(): print("Type:", shape["type"]) print("Color:", shape["color"]) print() + sh1 = shape.create_shape(shape) + print(sh1.perimetr()) + print(sh1.area()) return True diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/Rectangle.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/rectangle.py similarity index 67% rename from HNS/Excercises/13082023 ДЗ по фигурам JSON/Rectangle.py rename to HNS/Excercises/13082023 ДЗ по фигурам JSON/rectangle.py index b48e319..9d083bd 100644 --- a/HNS/Excercises/13082023 ДЗ по фигурам JSON/Rectangle.py +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/rectangle.py @@ -1,14 +1,17 @@ -from Shape import Shape +from shape import Shape class Rectangle(Shape): - def __int__(self, width, height, color): + def __init__(self, width, height): self.width = width self.height = height - self.color = color def area(self): return self.width * self.height def perimetr(self): return (self.width + self.height) * 2 + + +r1 = Rectangle(10, 20) +print(r1.area()) diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py new file mode 100644 index 0000000..6c99365 --- /dev/null +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py @@ -0,0 +1,28 @@ +from abc import abstractmethod +from abc import ABC + + +class Shape(ABC): + color = '' + + @abstractmethod + def area(self): + pass + + @abstractmethod + def perimetr(self): + pass + + @staticmethod + def create_shape(json): + if "type" in json: + shape_type = json["type"] + + if shape_type == "circle": + return Circle(json("radius")) + elif shape_type == "square": + return Square(json("side")) + elif shape_type == "rectangle": + return Rectangle(json["width"], json["height"]) + else: + raise TypeError(f'Неизвестная фигура {shape_type}') diff --git a/HNS/Excercises/13082023 ДЗ по фигурам JSON/Square.py b/HNS/Excercises/13082023 ДЗ по фигурам JSON/square.py similarity index 75% rename from HNS/Excercises/13082023 ДЗ по фигурам JSON/Square.py rename to HNS/Excercises/13082023 ДЗ по фигурам JSON/square.py index 8feb881..54da53b 100644 --- a/HNS/Excercises/13082023 ДЗ по фигурам JSON/Square.py +++ b/HNS/Excercises/13082023 ДЗ по фигурам JSON/square.py @@ -1,8 +1,8 @@ -from Shape import Shape +from shape import Shape class Square(Shape): - def __int__(self, side, color): + def __init__(self, side): self.side = side self.color = color