From e6cf680b0e9ad31749a7141e4bb4853370d8c61c Mon Sep 17 00:00:00 2001 From: "Daniil.K" Date: Tue, 30 Mar 2021 17:57:42 +0300 Subject: [PATCH] L-04: Add calculate.py and update docs --- calculate.py | 33 +++++++++++++++++++++++++++++++++ docs/README.md | 25 +++++++++++++++++-------- 2 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 calculate.py diff --git a/calculate.py b/calculate.py new file mode 100644 index 0000000..6dc22cf --- /dev/null +++ b/calculate.py @@ -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) + + + diff --git a/docs/README.md b/docs/README.md index 0825dac..209eaca 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,12 +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 ## Area -- Circle: S = πR² -- Rectangle: S = ab -- Square: S = a² -- Triangle: S = (a + b + c) / 2 +- Circle: `S = πR²` +- Rectangle: `S = ab` +- Square: `S = a²` +- Triangle: `S = sqrt(p * (p-a) * (p-b) * (p-c))` where p is semiperimeter ## Perimeter -- Circle: P = 2πR -- Rectangle: P = 2a + 2b -- Square: P = 4a -- Triangle: P = a + b + c +- Circle: `P = 2πR` +- Rectangle: `P = 2a + 2b` +- Square: `P = 4a` +- Triangle: `P = a + b + c` +