Загружаю первый рабочий вариант ДЗ по классам (без вызова класса в стат методе
This commit is contained in:
parent
f42cb4feda
commit
f8df1e5fa0
|
@ -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())
|
||||
|
|
|
@ -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()
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue