4 Commits
Author SHA1 Message Date
Daniil.K b5b0fae727 L-04: Update docs for calculate.py 2021-03-31 15:25:49 +03:00
Daniil.K d76db2ac7f L-04: Add calculate.py 2021-03-31 14:32:38 +03:00
smartiqa 51c40ebfd0 L-04: Doc updated for triangle 2021-03-26 14:52:26 +03:00
smartiqa d080c7888b L-04: Triangle added 2021-03-26 14:48:39 +03:00
3 changed files with 56 additions and 6 deletions
+33
View File
@@ -0,0 +1,33 @@
import circle
import square
figs = ['circle', 'square']
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}')
if __name__ == "__main__":
func = ''
fig = ''
size = list()
while fig not in figs:
fig = input(f"Enter figure name, avaliable are {figs}:\n")
while func not in funcs:
func = input(f"Enter function name, avaliable are {funcs}:\n")
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)
+17 -6
View File
@@ -1,10 +1,21 @@
# How to use calculator:
1. Run `python calculate.py`
2. Enter the figure name. Available are Circle, Square.
3. Enter the function: Area or Perimeter.
4. Enter figure sizes. Radius for circle, one side for square.
5. Get the answer!
# Math formulas # Math formulas
## Area ## Area
- Circle: S = πR² - Circle: `S = πR²`
- Rectangle: S = ab - Rectangle: `S = ab`
- Square: S = a² - Square: `S = a²`
- Triangle: `S = sqrt(p * (p-a) * (p-b) * (p-c))` where p is semiperimeter
## Perimeter ## Perimeter
- Circle: P = 2πR - Circle: `P = 2πR`
- Rectangle: P = 2a + 2b - Rectangle: `P = 2a + 2b`
- Square: P = 4a - Square: `P = 4a`
- Triangle: `P = a + b + c`
+6
View File
@@ -0,0 +1,6 @@
def area(a, b, c):
return (a + b + c) / 2
def perimeter(a, b, c):
return a + b + c