From f7ba5dcadb92a4b15a64d3ce4c553d4f2feaddc0 Mon Sep 17 00:00:00 2001 From: Daria Date: Wed, 13 Sep 2023 18:31:48 +0300 Subject: [PATCH 01/16] Created calculator.py with main function --- HW2_nekrasova/calculator.py | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 HW2_nekrasova/calculator.py diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py new file mode 100644 index 0000000..f5d0820 --- /dev/null +++ b/HW2_nekrasova/calculator.py @@ -0,0 +1,58 @@ +def main(expression: str): + expression_array = expression.split(' ') + array_of_operands = [] + + try: + left_int = int(expression_array[0]) + array_of_operands.append(left_int) + except: + left_float = float(expression_array[0]) + array_of_operands.append(left_float) + + + try: + right_int = int(expression_array[2]) + array_of_operands.append(right_int) + except: + left_float = float(expression_array[2]) + array_of_operands.append(left_float) + + answer = None + + if expression_array[1] == '+': + # answer = add(array_of_operands) + pass + elif expression_array[1] == '-': + # answer = substruct(array_of_operands) + pass + elif expression_array[1] == '*': + # answer = multiple(array_of_operands) + pass + elif expression_array[1] == '/': + # answer = divide(array_of_operands) + pass + + print(answer) + + +def add(arr_of_operands: list): + pass + + +def substruct(arr_of_operands: list): + pass + + +def multiple(arr_of_operands: list): + pass + + +def divide(arr_of_operands: list): + pass + + + + +current_expression = input() +main(current_expression) + From e9fc7bab716dc6b6ad7dd4127a0eb69b52be714c Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 13 Sep 2023 19:11:49 +0300 Subject: [PATCH 02/16] Update calculator.py --- HW2_nekrasova/calculator.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index f5d0820..162ed8d 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -29,7 +29,7 @@ def main(expression: str): # answer = multiple(array_of_operands) pass elif expression_array[1] == '/': - # answer = divide(array_of_operands) + answer = divide(array_of_operands) pass print(answer) @@ -44,7 +44,8 @@ def substruct(arr_of_operands: list): def multiple(arr_of_operands: list): - pass + answer = arr_of_operands[0] * arr_of_operands[1] + return answer def divide(arr_of_operands: list): From 32381dbe5d14959a6cd6eaf038433c11971994e9 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 13 Sep 2023 19:21:48 +0300 Subject: [PATCH 03/16] Update calculator.py --- HW2_nekrasova/calculator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index 162ed8d..a2f3f0b 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -26,10 +26,10 @@ def main(expression: str): # answer = substruct(array_of_operands) pass elif expression_array[1] == '*': - # answer = multiple(array_of_operands) + answer = multiple(array_of_operands) pass elif expression_array[1] == '/': - answer = divide(array_of_operands) + # answer = divide(array_of_operands) pass print(answer) From d3ca03d94e9b7e17aa6bbb7cbd02450d3f9c0331 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 13 Sep 2023 19:22:53 +0300 Subject: [PATCH 04/16] Revert "Update calculator.py" This reverts commit 32381dbe5d14959a6cd6eaf038433c11971994e9. --- HW2_nekrasova/calculator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index a2f3f0b..162ed8d 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -26,10 +26,10 @@ def main(expression: str): # answer = substruct(array_of_operands) pass elif expression_array[1] == '*': - answer = multiple(array_of_operands) + # answer = multiple(array_of_operands) pass elif expression_array[1] == '/': - # answer = divide(array_of_operands) + answer = divide(array_of_operands) pass print(answer) From b672eb9c3e2f65622bc7e6291c0fd48fac1dce6b Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 13 Sep 2023 19:30:49 +0300 Subject: [PATCH 05/16] Add multiple function to calculator.py --- HW2_nekrasova/calculator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index 162ed8d..a2f3f0b 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -26,10 +26,10 @@ def main(expression: str): # answer = substruct(array_of_operands) pass elif expression_array[1] == '*': - # answer = multiple(array_of_operands) + answer = multiple(array_of_operands) pass elif expression_array[1] == '/': - answer = divide(array_of_operands) + # answer = divide(array_of_operands) pass print(answer) From 4f7eae892d573b4c1c58a2aac2776cfd5fb3035b Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 13 Sep 2023 19:48:54 +0300 Subject: [PATCH 06/16] Minor code review --- HW2_nekrasova/calculator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index a2f3f0b..31e8a1e 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -27,7 +27,6 @@ def main(expression: str): pass elif expression_array[1] == '*': answer = multiple(array_of_operands) - pass elif expression_array[1] == '/': # answer = divide(array_of_operands) pass From 22d6854e0a34a868ff46d7ed886ae502d42a05f9 Mon Sep 17 00:00:00 2001 From: anya Date: Thu, 14 Sep 2023 00:29:53 +0700 Subject: [PATCH 07/16] Add substruct function --- HW2_nekrasova/calculator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index f5d0820..303751b 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -23,8 +23,8 @@ def main(expression: str): # answer = add(array_of_operands) pass elif expression_array[1] == '-': - # answer = substruct(array_of_operands) - pass + answer = substruct(array_of_operands) + elif expression_array[1] == '*': # answer = multiple(array_of_operands) pass @@ -40,7 +40,8 @@ def add(arr_of_operands: list): def substruct(arr_of_operands: list): - pass + # substruct + return arr_of_operands[0]-arr_of_operands[1] def multiple(arr_of_operands: list): From 98ee4376d91e1446c56ee6c0d27db2604fdf67ea Mon Sep 17 00:00:00 2001 From: Irina Grishchenko Date: Wed, 13 Sep 2023 20:35:46 +0300 Subject: [PATCH 08/16] Add def divide in calculator.py --- HW2_nekrasova/calculator.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index f5d0820..16035ca 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -29,8 +29,7 @@ def main(expression: str): # answer = multiple(array_of_operands) pass elif expression_array[1] == '/': - # answer = divide(array_of_operands) - pass + answer = divide(array_of_operands) print(answer) @@ -48,7 +47,11 @@ def multiple(arr_of_operands: list): def divide(arr_of_operands: list): - pass + if expression_array[2] != 0: + ans = expression_array[0]/expression_array[2] + return ans + else: + return print ('Деление на 0') From 9c2723da2cba7d5316fc7897d7091e928ccca666 Mon Sep 17 00:00:00 2001 From: Irina Grishchenko Date: Wed, 13 Sep 2023 21:03:40 +0300 Subject: [PATCH 09/16] Add modification in def divide --- HW2_nekrasova/calculator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index 16035ca..d418895 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -47,11 +47,11 @@ def multiple(arr_of_operands: list): def divide(arr_of_operands: list): - if expression_array[2] != 0: - ans = expression_array[0]/expression_array[2] - return ans + if arr_of_operands[1] != 0: + answer = arr_of_operands[0]/arr_of_operands[1] + return answer else: - return print ('Деление на 0') + answer = 'Деление на 0!' From 1b1799a5803ed0a82e6fd46dec8196051c35d2c7 Mon Sep 17 00:00:00 2001 From: Irina Grishchenko Date: Wed, 13 Sep 2023 21:48:04 +0300 Subject: [PATCH 10/16] Add new modification in def divide --- HW2_nekrasova/calculator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index d418895..77eb82f 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -49,9 +49,10 @@ def multiple(arr_of_operands: list): def divide(arr_of_operands: list): if arr_of_operands[1] != 0: answer = arr_of_operands[0]/arr_of_operands[1] - return answer + return answer else: answer = 'Деление на 0!' + return answer From aa0d07d87bead0a5d3de6b5c14483cdbea603729 Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 14 Sep 2023 12:01:51 +0300 Subject: [PATCH 11/16] Create README.md --- HW2_nekrasova/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 HW2_nekrasova/README.md diff --git a/HW2_nekrasova/README.md b/HW2_nekrasova/README.md new file mode 100644 index 0000000..672eb83 --- /dev/null +++ b/HW2_nekrasova/README.md @@ -0,0 +1,20 @@ +# Basic calculator +* This repo is for the 2nd homework of Python 2023 course* + +### Calculator description +This branch (HW2_nekrasova) contains calculator.py script designed to operate with two numbers via one of the following basic mathematical functions: addition, subtraction, multiplication, division. +Right after start script waits for the user to enter a mathematical expression like '2 * 2'. Expression is then splitted by spaces and calculated corresponding to function according to the specified operator. +The script handles both int and float types of numbers. It also handles devision by 0. + +### Installation +Calculator is a straight forward script that does not need any prerequisites apart from installed Python 3. To get started use your CLI and execute the following commandlet: `python3 calculator.py`. +After this the script is ready to recieve your mathematical expression. + +### Development +This project is leaded by Nekrasova D. with contributions from the following people: +- grishchenkoira +- anisssum +- NSapozhnikov +- Komarov I. + +Feel free to report any bugs encountered to nekrasovadasha22. From 477c5395f87811314bed6b8170be5d65c2b3a2bf Mon Sep 17 00:00:00 2001 From: Nikita <81642791+NSapozhnikov@users.noreply.github.com> Date: Thu, 14 Sep 2023 12:05:20 +0300 Subject: [PATCH 12/16] Update README.md --- HW2_nekrasova/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HW2_nekrasova/README.md b/HW2_nekrasova/README.md index 672eb83..ebe4646 100644 --- a/HW2_nekrasova/README.md +++ b/HW2_nekrasova/README.md @@ -1,5 +1,5 @@ # Basic calculator -* This repo is for the 2nd homework of Python 2023 course* +*This repo is for the 2nd homework of Python 2023 course* ### Calculator description This branch (HW2_nekrasova) contains calculator.py script designed to operate with two numbers via one of the following basic mathematical functions: addition, subtraction, multiplication, division. @@ -11,7 +11,7 @@ Calculator is a straight forward script that does not need any prerequisites apa After this the script is ready to recieve your mathematical expression. ### Development -This project is leaded by Nekrasova D. with contributions from the following people: +This project is leaded by nekrasovadasha22 with contributions from the following people: - grishchenkoira - anisssum - NSapozhnikov From beb16845328bba56755add49551ae33e8e94498d Mon Sep 17 00:00:00 2001 From: Ilya Komarkov Date: Thu, 14 Sep 2023 17:50:08 +0300 Subject: [PATCH 13/16] Add addition function --- HW2_nekrasova/calculator.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index f5d0820..fb4536e 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -20,10 +20,10 @@ def main(expression: str): answer = None if expression_array[1] == '+': - # answer = add(array_of_operands) - pass + answer = add(array_of_operands) + elif expression_array[1] == '-': - # answer = substruct(array_of_operands) + answer = substruct(array_of_operands) pass elif expression_array[1] == '*': # answer = multiple(array_of_operands) @@ -36,8 +36,7 @@ def main(expression: str): def add(arr_of_operands: list): - pass - + return arr_of_operands[0] + arr_of_operands[2] def substruct(arr_of_operands: list): pass From a94dcb29bf5c04bf9975b10d52509ea47e0d0fb2 Mon Sep 17 00:00:00 2001 From: Ilya Komarkov Date: Thu, 14 Sep 2023 18:23:36 +0300 Subject: [PATCH 14/16] Fix string in add function --- HW2_nekrasova/calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index fb4536e..b1d86b6 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -36,7 +36,7 @@ def main(expression: str): def add(arr_of_operands: list): - return arr_of_operands[0] + arr_of_operands[2] + return arr_of_operands[0]+arr_of_operands[2] def substruct(arr_of_operands: list): pass From d2d7380e0041aa36a0851933477bb5ba578d4515 Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 14 Sep 2023 20:47:43 +0300 Subject: [PATCH 15/16] fix little bugs --- .gitignore | 1 + HW2_nekrasova/calculator.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c2d52b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/* diff --git a/HW2_nekrasova/calculator.py b/HW2_nekrasova/calculator.py index 7d8024f..cf4115f 100644 --- a/HW2_nekrasova/calculator.py +++ b/HW2_nekrasova/calculator.py @@ -14,8 +14,8 @@ def main(expression: str): right_int = int(expression_array[2]) array_of_operands.append(right_int) except: - left_float = float(expression_array[2]) - array_of_operands.append(left_float) + right_float = float(expression_array[2]) + array_of_operands.append(right_float) answer = None @@ -34,7 +34,7 @@ def main(expression: str): def add(arr_of_operands: list): - return arr_of_operands[0]+arr_of_operands[2] + return arr_of_operands[0]+arr_of_operands[1] def substruct(arr_of_operands: list): # substruct @@ -52,7 +52,7 @@ def divide(arr_of_operands: list): return answer else: answer = 'Деление на 0!' - return answer + return answer From 977549a4d071c529f166af18dc04d1a640892c67 Mon Sep 17 00:00:00 2001 From: nekrasovadasha22 <144455860+nekrasovadasha22@users.noreply.github.com> Date: Thu, 14 Sep 2023 20:57:09 +0300 Subject: [PATCH 16/16] Update README.md Added team photo --- HW2_nekrasova/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/HW2_nekrasova/README.md b/HW2_nekrasova/README.md index ebe4646..3e5bacd 100644 --- a/HW2_nekrasova/README.md +++ b/HW2_nekrasova/README.md @@ -18,3 +18,4 @@ This project is leaded by nekrasovadasha22 with contributions from the following - Komarov I. Feel free to report any bugs encountered to nekrasovadasha22. +![photo_2023-09-13_19-43-30](https://github.com/nekrasovadasha22/HW2_Git_and_python/assets/144455860/d11f2906-21e0-4eda-9849-b58d64b312c8)