From cee915fac3e49c3d6eb34749781b97573f06cdbb Mon Sep 17 00:00:00 2001 From: iravasu Date: Wed, 9 Oct 2024 23:06:56 +0300 Subject: [PATCH 1/2] added new files with izmenenia --- calculate.py | 15 ++++++++++++++- circle.py | 6 ++++++ square.py | 7 ++++++- triangle.py | 6 ++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/calculate.py b/calculate.py index 6dc22cf12..bba40358e 100644 --- a/calculate.py +++ b/calculate.py @@ -1,3 +1,4 @@ +# Импорт модулей для работы с кругом и квадратом import circle import square @@ -6,10 +7,15 @@ funcs = ['perimeter', 'area'] sizes = {} +# Функция для вычисления указанной функции для фигуры def calc(fig, func, size): + #Вычисление функции для фигуры на основе ее размера. + + # Проверка корректности входных данных assert fig in figs assert func in funcs + # Выполнение вычисления и вывод результата result = eval(f'{fig}.{func}(*{size})') print(f'{func} of {fig} is {result}') @@ -18,6 +24,7 @@ def calc(fig, func, size): fig = '' size = list() + # Ввод фигуры, функции и размеров с проверками while fig not in figs: fig = input(f"Enter figure name, avaliable are {figs}:\n") @@ -27,7 +34,13 @@ def calc(fig, func, size): while len(size) != sizes.get(f"{func}-{fig}", 1): size = list(map(int, input("Input figure sizes separated by space, 1 for circle and square\n").split(' '))) - calc(fig, func, size) + calc(fig, func, size) # Вычисление и вывод результата + + # Пример вызова: вычисление периметра круга с радиусом 5 + # calc('circle', 'perimeter', [5]) # Результат: perimeter of circle is 31.41592653589793 + + # Пример вызова: вычисление площади квадрата со стороной 4 + # calc('square', 'area', [4]) # Результат: area of square is 16 diff --git a/circle.py b/circle.py index c3eb8647c..ddf6291c2 100644 --- a/circle.py +++ b/circle.py @@ -2,9 +2,15 @@ def area(r): + #Вычисляет площадь круга по заданному радиусу. return math.pi * r * r def perimeter(r): + #Вычисляет длинну окружности по заданному радиусу. return 2 * math.pi * r +#area(5) Результат: 78.53981633974483 +#perimeter(5) Результат: 31.41592653589793 + + diff --git a/square.py b/square.py index 0f9872420..8ed3ec688 100644 --- a/square.py +++ b/square.py @@ -1,7 +1,12 @@ - def area(a): + #Вычисляет площадь квадрата по заданнойдлине стороны return a * a def perimeter(a): + #Вычисляет периметр квадрата по задданой длине стороны return 4 * a + +#area(4) Результат: 16 +#perimeter(4) Результат: 16 + diff --git a/triangle.py b/triangle.py index fb41f60a5..4c7760dfa 100644 --- a/triangle.py +++ b/triangle.py @@ -1,6 +1,12 @@ def area(a, b, c): + #Вычисляет полупериметр треугольника по заданным длинам сторон. return (a + b + c) / 2 def perimeter(a, b, c): + #Вычисляет периметр треугольника по заданым длинам сторон return a + b + c + +#area(3, 4, 5) Результат: 6.0 +#perimeter(3, 4, 5) Результат: 12 + From 1bdec7cc1c04713fb57909ac9013be3643c66883 Mon Sep 17 00:00:00 2001 From: iravasu Date: Wed, 9 Oct 2024 23:32:58 +0300 Subject: [PATCH 2/2] changed READ.ME file --- docs/README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docs/README.md b/docs/README.md index 209eaca53..a4d2a164a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,3 +19,67 @@ - Square: `P = 4a` - Triangle: `P = a + b + c` + + + +# Functions, description and examples +## `calculate.py` +### 'def calc(fig, func, size):' +- Calculates the value of the specified function for the specified shape based on its dimensions. +- Example of a call: +```python +>> calc('circle', 'area', [5]) +78.53981633974483 +``` +## `circle.py` +### `def area(r):` +- Calculates the area of a circle by a given radius. +- Example of a call: +```python +>> area(5) +78.53981633974483 +``` +### `def perimeter(r):` +- Calculates the length of a circle (the perimeter of a circle) by a given radius. +- Example of a call: +```python +>> perimeter (5) +31.41592653589793 +``` +## `square.py` +### `def area(a):` +- Calculates the area of a square along a given side length. +- Example of a call: +```python +>> area(5) +25 +``` +### `def perimeter(a):` +- Calculates the perimeter of a square along a given side length. +- Example of a call: +```python +>> perimeter (5) +20 +``` +## `triangle.py` +### `def area(a, b, c):` +- Calculates the half-meter (not the area) of a triangle by the specified side lengths. +- Example of a call: +```python +>> area (3, 4, 5) +6.0 +``` +### `def perimeter(a, b, c)` +- Calculate the perimeter of a triangle from given side lengths. +- Example of a call: +```python +>> perimetr (3, 4, 5) +12 +``` +# The history of changing the project eiyj the hashed of thr comits +1. **8ba9aeb** L-03: Circle and square added +2. **d078c8d** L-03: Docs added +3. **d080c78** L-04: Triangle added +4. **51c40eb** L-04: Doc updated for triangle +5. **d76db2a** L-04: Add calculate.py +6. **b5b0fae** L-04: Update docs for calculate.py \ No newline at end of file