diff --git a/HW2_Spirin/2025_09_15_20439.png b/HW2_Spirin/2025_09_15_20439.png new file mode 100644 index 0000000..7bfee91 Binary files /dev/null and b/HW2_Spirin/2025_09_15_20439.png differ diff --git a/HW2_Spirin/README.md b/HW2_Spirin/README.md new file mode 100644 index 0000000..8012064 --- /dev/null +++ b/HW2_Spirin/README.md @@ -0,0 +1,18 @@ +# HW2_Git_and_python + +We have written a mini-program `calculator.py `. The program accepts input (via `input()`) a string with some mathematical expression and prints a number - the result of calculating this expression. +The expression must consist of two numbers (`int` or `float`) and a mathematical operator between them (one of 4: `+ - * /`). All the specified elements are separated by spaces (example: `5 - 3`). + +There are 5 functions implemented inside the script: `main' (which accepts the input expression) and 4 functions for each type of mathematical operations (addition, subtraction, multiplication and division). + +✨✨✨✨✨ +Our team: + +Danil Spirin +Anastasiia Sycheva +Margarita Lantsova +Daria Chekanova +Andrey Nekrasov +✨✨✨✨✨ + +![Photo of a joint call](./2025_09_15_20439.png) diff --git a/HW2_Spirin/calculator.py b/HW2_Spirin/calculator.py new file mode 100755 index 0000000..d15c42f --- /dev/null +++ b/HW2_Spirin/calculator.py @@ -0,0 +1,43 @@ +# def functions + +def mult_fun(n1, n2): + res = n1 * n2 + return res + +def subtr_fun(n1, n2): + res = n1 - n2 + return res + +def add_fun(n1, n2): + return n1 + n2 + +def div_fun(n1, n2): + if n2 == 0: + res = 'You cannot divide by Zero' + else: + res = n1 / n2 + return res + + +def main_fun(i): + n1, operator, n2 = i.split() + + n1 = float(n1) + n2 = float(n2) + + if operator == '+': + res = add_fun(n1, n2) # Addition + + elif operator == '-': + res = subtr_fun(n1, n2) # Subtraction + + elif operator == '*': + res = mult_fun(n1, n2) # Multiplication + + elif operator == '/': + res = div_fun(n1, n2) # Division - add condition for "Division by zero!" + + print(res) + +input_ = input() +main_fun(input_)