добвил ДЗ

This commit is contained in:
vitalii Malcov 2023-08-22 07:29:06 +02:00
parent 35d4125455
commit e1ac706159
4 changed files with 76 additions and 6 deletions

View File

@ -0,0 +1,20 @@
{
"shapes": [
{
"type": "rectangle",
"width": 5,
"height": 10,
"color": "red"
},
{
"type": "circle",
"radius": 7,
"color": "blue"
},
{
"type": "square",
"side": 4,
"color": "green"
}
]
}

View File

@ -0,0 +1,42 @@
import json
import math
class Shape:
def aria(self):
return -1
def perimeter(self):
return -2
class Rectangle(Shape):
def __init__(self, w, h):
self.w = w
self.h = h
def perimeter(self):
return 2 * (self.w + self.h)
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
def aria(self):
return math.pi + (self.radius ** 2)
class Square(Shape):
def __init__(self, a):
self.a = a
def perimeter(self):
return 4 * self.a
def json_to_python():
while open('shapes.json') as shapes:
data = json.loads(shapes)
return data

View File

@ -0,0 +1,11 @@
import json
def json_to_python():
while open('shapes.json') as shapes:
data = json.load(shapes)
return data
obj = json_to_python()
for shapes in obj['shapes']:
print(shapes)

View File

@ -15,6 +15,8 @@ def verifier(message, actual, expected):
def verify_all(dataset): def verify_all(dataset):
summa_success = int() summa_success = int()
summa_failed = int() summa_failed = int()
for i in range(len(dataset)):
verifier(f"min_array_datatest {i + 1}", min_array(dataset[i][0]), dataset[i][1])
print("Total:", len(dataset), "Successful:", summa_success, "Failed:", summa_failed) print("Total:", len(dataset), "Successful:", summa_success, "Failed:", summa_failed)
return True return True
@ -40,9 +42,4 @@ array = [2, 3, 5, 8, 89, 65, 75, 7895, 2, 1, 1]
dataset = [("Test1", 3, min_array(array)), ("Test2", 7895, max_array(array))] dataset = [("Test1", 3, min_array(array)), ("Test2", 7895, max_array(array))]
for i in range(len(dataset)): verify_all(dataset)
verifier(f"max_array_datatest {i+1}", max_array(dataset[i][0]), dataset[i][1])
for i in range(len(dataset)):
verifier(f"min_array_datatest {i+1}", min_array(dataset[i][0]), dataset[i][1])