diff --git a/.DS_Store b/.DS_Store index 488c284..4b6330a 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/HNS/.DS_Store b/HNS/.DS_Store index c53f210..7391456 100644 Binary files a/HNS/.DS_Store and b/HNS/.DS_Store differ diff --git a/HNS/Excercises/.DS_Store b/HNS/Excercises/.DS_Store index 7e583a9..5794bfe 100644 Binary files a/HNS/Excercises/.DS_Store and b/HNS/Excercises/.DS_Store differ 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