From e1ac706159f8cf852e5ee9545de39082deedcb68 Mon Sep 17 00:00:00 2001 From: vitalii Malcov Date: Tue, 22 Aug 2023 07:29:06 +0200 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B2=D0=B8=D0=BB=20=D0=94?= =?UTF-8?q?=D0=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NHC/Excercises/22,08,2023/shapes.json | 20 ++++++++++ NHC/Excercises/22,08,2023/ДЗ 22,08,2023.py | 42 ++++++++++++++++++++ NHC/Excercises/22,08,2023/ДЗ 22,08,2023_2.py | 11 +++++ NHC/Excercises/дз 25,07,2023.py | 9 ++--- 4 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 NHC/Excercises/22,08,2023/shapes.json create mode 100644 NHC/Excercises/22,08,2023/ДЗ 22,08,2023.py create mode 100644 NHC/Excercises/22,08,2023/ДЗ 22,08,2023_2.py diff --git a/NHC/Excercises/22,08,2023/shapes.json b/NHC/Excercises/22,08,2023/shapes.json new file mode 100644 index 0000000..7661371 --- /dev/null +++ b/NHC/Excercises/22,08,2023/shapes.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/NHC/Excercises/22,08,2023/ДЗ 22,08,2023.py b/NHC/Excercises/22,08,2023/ДЗ 22,08,2023.py new file mode 100644 index 0000000..8cba95c --- /dev/null +++ b/NHC/Excercises/22,08,2023/ДЗ 22,08,2023.py @@ -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 + diff --git a/NHC/Excercises/22,08,2023/ДЗ 22,08,2023_2.py b/NHC/Excercises/22,08,2023/ДЗ 22,08,2023_2.py new file mode 100644 index 0000000..787bfbc --- /dev/null +++ b/NHC/Excercises/22,08,2023/ДЗ 22,08,2023_2.py @@ -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) diff --git a/NHC/Excercises/дз 25,07,2023.py b/NHC/Excercises/дз 25,07,2023.py index 31da53b..ae77d53 100644 --- a/NHC/Excercises/дз 25,07,2023.py +++ b/NHC/Excercises/дз 25,07,2023.py @@ -15,6 +15,8 @@ def verifier(message, actual, expected): def verify_all(dataset): summa_success = 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) 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))] -for i in range(len(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]) - +verify_all(dataset)