Загружаю файлы с добавленным функционалом по классам
This commit is contained in:
parent
e01eb1aeb0
commit
f42cb4feda
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
|
@ -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>
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -1,7 +0,0 @@
|
|||
|
||||
class Shape:
|
||||
def area(self):
|
||||
return NotImplementedError("Необходимо переопределить метод area в дочернем классе")
|
||||
|
||||
def perimetr(self):
|
||||
return NotImplementedError("Необходимо переопределить метод perimetr в дочернем классе")
|
|
@ -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)
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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())
|
|
@ -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}')
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue