Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion calculate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Импорт модулей для работы с кругом и квадратом
import circle
import square

Expand All @@ -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}')

Expand All @@ -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")

Expand All @@ -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



6 changes: 6 additions & 0 deletions circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


64 changes: 64 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion square.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

def area(a):
#Вычисляет площадь квадрата по заданнойдлине стороны
return a * a


def perimeter(a):
#Вычисляет периметр квадрата по задданой длине стороны
return 4 * a

#area(4) Результат: 16
#perimeter(4) Результат: 16

6 changes: 6 additions & 0 deletions triangle.py
Original file line number Diff line number Diff line change
@@ -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