Загружаю файлы с добавленным функционалом по классам

This commit is contained in:
ehermakov 2023-08-27 15:12:28 +03:00
parent e01eb1aeb0
commit f42cb4feda
15 changed files with 77 additions and 15 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
HNS/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/13082023 ДЗ по фигурам JSON.iml" filepath="$PROJECT_DIR$/.idea/13082023 ДЗ по фигурам JSON.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>

View File

@ -1,7 +0,0 @@
class Shape:
def area(self):
return NotImplementedError("Необходимо переопределить метод area в дочернем классе")
def perimetr(self):
return NotImplementedError("Необходимо переопределить метод perimetr в дочернем классе")

View File

@ -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)

View File

@ -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

View File

@ -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())

View File

@ -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}')

View File

@ -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