diff --git a/HW2_Mirny/README.md b/HW2_Mirny/README.md new file mode 100644 index 0000000..8af5f83 --- /dev/null +++ b/HW2_Mirny/README.md @@ -0,0 +1,28 @@ +# HW2_Mirny - Calculator + +## Description + +This project is Homework 2 for the "Bioinformatics Institute" bioinformatics program. + +The program `calculator.py` reads a mathematical expression in the format: +` ` + + +where `` is one of: `+`, `-`, `*`, `/`. +The program calculates the result and prints it to the screen. + +## Examples +5 - 3 -> 2 + +10 / 2 -> 5.0 + +## Team members + +- Mark Mirny (team lead, @head-ease08): addition +- Anton Goncharov (@TonyGoncharov): main, division +- Sergey Ilin (@SergeyIlin322): multiplication +- Liubov Minina (@liuminin): subtraction, README + +## Team call screenshot +![Team call](./imgs/team_call.png) + diff --git a/HW2_Mirny/calculator.py b/HW2_Mirny/calculator.py new file mode 100644 index 0000000..5d4ecc1 --- /dev/null +++ b/HW2_Mirny/calculator.py @@ -0,0 +1,40 @@ +def add(a, b): + return a + b + +def mul(a, b): + return a * b + +def sub(a, b): + return a - b + +def div(a, b): + try: + return a / b + except ZeroDivisionError: + return('Error! Zero division!') + +def main(): + expr = input('Enter expression.\n').strip() + a_str, op, b_str = expr.split() + + try: + a, b = float(a_str), float(b_str) + except ValueError: + print('Error: You must enter numbers.') + return + + if op == '+': + result = add(a, b) + elif op == '-': + result = sub(a, b) + elif op == '*': + result = mul(a, b) + elif op == '/': + result = div(a, b) + else: + result = 'Unsupported operator. Only one of: + - * /' + + print(result) + +if __name__ == "__main__": + main() diff --git a/HW2_Mirny/imgs/team_call.png b/HW2_Mirny/imgs/team_call.png new file mode 100644 index 0000000..21a65ce Binary files /dev/null and b/HW2_Mirny/imgs/team_call.png differ