From e20efee0fc77738662c2b59a6ee8ea282562b612 Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Wed, 5 Jun 2019 22:52:40 +0300 Subject: [PATCH 01/17] create function parse math parameters create function parse expression with brackets calculate expression in work!!! --- .idea/inspectionProfiles/Project_Default.xml | 17 ++++ .idea/vcs.xml | 6 ++ final_task/arithmetic.py | 28 ++++++ final_task/calculate_expression.py | 76 ++++++++++++++++ final_task/calculate_math_parameters.py | 84 +++++++++++++++++ final_task/parse_brackets.py | 44 +++++++++ final_task/pycalc.py | 95 ++++++++++++++++++++ final_task/pycalc_common.py | 20 +++++ 8 files changed, 370 insertions(+) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/vcs.xml create mode 100644 final_task/arithmetic.py create mode 100644 final_task/calculate_expression.py create mode 100644 final_task/calculate_math_parameters.py create mode 100644 final_task/parse_brackets.py create mode 100644 final_task/pycalc.py create mode 100644 final_task/pycalc_common.py diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..c825f3de --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/final_task/arithmetic.py b/final_task/arithmetic.py new file mode 100644 index 00000000..894f8ac6 --- /dev/null +++ b/final_task/arithmetic.py @@ -0,0 +1,28 @@ +def subtraction(first_parameter, second_parameter): + return float(first_parameter) - float(second_parameter) + + +def add(first_parameter, second_parameter): + return float(first_parameter) + float(second_parameter) + + +def multiply(first_parameter, second_parameter): + return float(first_parameter) * float(second_parameter) + + +def division(first_parameter, second_parameter): + if float(second_parameter) == 0: + return "Error: division by zero" + return float(first_parameter) / float(second_parameter) + + +def power(first_parameter, second_parameter): + return float(first_parameter) ** float(second_parameter) + + +def integer_division(first_parameter, second_parameter): + return float(first_parameter) // float(second_parameter) + + +def modulo_division(first_parameter, second_parameter): + return float(first_parameter) % float(second_parameter) diff --git a/final_task/calculate_expression.py b/final_task/calculate_expression.py new file mode 100644 index 00000000..d69c3d14 --- /dev/null +++ b/final_task/calculate_expression.py @@ -0,0 +1,76 @@ +import arithmetic +import re +import math + + +def calculate(value): + """ It is a calculator. It can be use Math operation""" + + if type(value) is not str: + print('It expected str got ' + type(value).__name__) + + access_operators = ['+', '-', '*', '/', '//', '%', '**'] + operators = re.findall(r'(\D*[^-.?\d?])', value) + digits = re.findall(r'(-*\.*\d+\.*\d*)', value) + if len(operators) == len(digits): + return "Error: you miss digits" + # check accessible operators + for operator in operators: + format_operator = operator.replace(' ', '') + if format_operator not in access_operators: + return "Error: not accessible operator '" + operator + "'" + + counter = 0 + result = 0 + rest_operator = [] + rest_digits = [] + check = False + # look for priority operators + for operator in operators: + format_operator = operator.replace(' ', '') + + if format_operator == '/' or format_operator == '*' or format_operator == '//' or format_operator == '%' or format_operator == '**': + first_parameter = digits[counter] + if check: + first_parameter = rest_digits[-1] + if format_operator == '*': + result = arithmetic.multiply(first_parameter, digits[counter + 1]) + elif format_operator == '/': + result = arithmetic.division(first_parameter, digits[counter + 1]) + if type(result) is str: + return result + elif format_operator == '//': + result = arithmetic.integer_division(first_parameter, digits[counter + 1]) + elif format_operator == '%': + result = arithmetic.modulo_division(first_parameter, digits[counter + 1]) + elif format_operator == '**': + result = arithmetic.power(first_parameter, digits[counter + 1]) + if counter != 0: + rest_digits[-1] = result + else: + rest_digits.append(result) + check = True + else: + rest_operator.append(format_operator) + if counter == 0: + rest_digits.append(digits[counter]) + rest_digits.append(digits[counter + 1]) + check = False + counter += 1 + if len(rest_operator) == 0: + # return value + if len(rest_digits) > 0: + return rest_digits[0] + else: + return value + else: + result = rest_digits[0] + counter2 = 0 + for operator in rest_operator: + format_operator = operator.replace(' ', '') + if format_operator == '+': + result = arithmetic.add(result, rest_digits[counter2 + 1]) + elif format_operator == '-': + result = arithmetic.subtraction(result, rest_digits[counter2 + 1]) + counter2 += 1 + return result \ No newline at end of file diff --git a/final_task/calculate_math_parameters.py b/final_task/calculate_math_parameters.py new file mode 100644 index 00000000..fa13290d --- /dev/null +++ b/final_task/calculate_math_parameters.py @@ -0,0 +1,84 @@ +import math +import re +import builtins +import calculate_expression +import parse_brackets + +math_param = dir(math) +additional_param = ['abs', 'round'] +all_parameters = math_param + additional_param + + +def calc_math(name, value): + if value.find(',') == -1: + result = getattr(math, name)( + float(calculate_expression.calculate("".join(parse_brackets.parse_brackets(value))))) + else: + new_value = value.split(',') + result = getattr(math, name)( + float(calculate_expression.calculate("".join(parse_brackets.parse_brackets(new_value[0])))), + float(calculate_expression.calculate("".join(parse_brackets.parse_brackets(new_value[1]))))) + return result + + +def cal_additional_parameters(name, value): + return getattr(builtins, name)(float(eval(value))) + + +# input: value - string expression +# output: string with calculated parameters +def calculate_math_parameters(value): + value = value.replace('pi', str(math.pi)).replace('e', str(math.e)) + + math_parameters_from_expression = re.findall(r'(\w+)\s*\((.+)\)', value) + value = value.replace(' (', '(') + + for items in math_parameters_from_expression: + new_item_name = items[0] + new_item_value = items[1] + if new_item_name not in all_parameters: + return 'Error: parameter "' + new_item_name + '" not found' + if items[0] in additional_param: + value = value.replace(items[0] + '(' + items[1] + ')', + str(cal_additional_parameters(new_item_name, new_item_value))) + else: + value = value.replace(items[0] + '(' + items[1] + ')', str(calc_math(new_item_name, new_item_value))) + + return value + + +def calc_math_parameter(value): + + result = [] + temp = "" + previous_element = "" + for item in value: + if re.match(r'[a-z]', item) and not re.match(r'[a-z]', previous_element): + if len(temp) > 0: + result.append(temp) + temp = "" + temp += item + if item == ')': + if len(temp) > 0: + if temp.find('(') != -1 and temp.find(')') != -1: + count_left_bracket = re.findall(r'\(', temp) + count_right_bracket = re.findall(r'\)', temp) + if len(count_left_bracket) == len(count_right_bracket): + if len(result) > 0: + if result[-1].find('(') != -1: + temp = result[-1] + str(calculate_math_parameters(temp)) + del result[-1] + else: + temp = str(calculate_math_parameters(temp)) + result.append(temp) + temp = "" + else: + temp = str(calculate_math_parameters(temp)) + result.append(temp) + temp = "" + else: + result.append(temp) + temp = "" + previous_element = item + return result + diff --git a/final_task/parse_brackets.py b/final_task/parse_brackets.py new file mode 100644 index 00000000..9e3b99f4 --- /dev/null +++ b/final_task/parse_brackets.py @@ -0,0 +1,44 @@ +import math +import calculate_expression + + +def parse_brackets(value): + result = [] + temp = "" + is_calculate_expression = False + counter_value = 1 + for item in value: + if item == '(' or item == ')': + if item == ')': + temp += item + if len(temp) > 0: + if temp.find('(') != -1 and temp.find(')') != -1: + temp = temp.replace('(', '').replace(')', '') + if len(result) > 0: + if result[-1].find('(') != -1: + temp = result[-1] + str(calculate_expression.calculate(temp)) + del result[-1] + else: + temp = str(calculate_expression.calculate(temp)) + result.append(temp) + temp = "" + is_calculate_expression = True + else: + temp = str(calculate_expression.calculate(temp)) + result.append(temp) + else: + result.append(temp) + temp = "" + else: + if len(value) == counter_value: + temp += item + result.append(temp) + temp += item + if item == ')' and not is_calculate_expression: + temp = "" + elif is_calculate_expression: + temp = temp[:-1] + is_calculate_expression = False + counter_value += 1 + result = ''.join(result) + return result diff --git a/final_task/pycalc.py b/final_task/pycalc.py new file mode 100644 index 00000000..2985b150 --- /dev/null +++ b/final_task/pycalc.py @@ -0,0 +1,95 @@ +import argparse +import re +import pycalc_common +# from math import * + +parser = argparse.ArgumentParser() +parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") +parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") +args = parser.parse_args() +if args.EXPRESSION: + print(pycalc_common.pcalc(args.EXPRESSION)) + +# print(pycalc_common.pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) +# def pcalc(value): +# left_bracket = re.findall(r'\(', value) +# right_bracket = re.findall(r'\)', value) +# if len(left_bracket) != len(right_bracket): +# return 'error: missing bracket' +# +# result_calculate = calculate_math_parameters.calculate_math_parameters(value) +# +# print('result_calculate', result_calculate) +# if len(left_bracket) or len(right_bracket): +# result = parse_brackets.parse_brackets(result_calculate) +# else: +# result = eval(value) +# # print('eval_result:', eval(value)) +# print('my_result:', result) +# return result + + +# print(pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) +# print(sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))) +# print(calculate_expression.calculate('2.718281828459045**2.718281828459045**-0.8462204041751706')) +# print(2.718281828459045**2.718281828459045**-0.8462204041751706) +# print(2.718281828459045**-0.8462204041751706) +# print(2.718281828459045**0.4290334443756452) +# print(calculate_expression.calculate('5**2')) +# print(calc_math('sin(-cos(-sin(3.0)-cos(-sin(-3.0*5.0)-sin(cos(log10(43.0))))+cos(sin(sin(34.0-2.0**2.0))))--cos(1.0)--cos(0.0)**3.0)')) +# print(sin(-cos(-sin(3.0)-cos(-sin(-3.0*5.0)-sin(cos(log10(43.0))))+cos(sin(sin(34.0-2.0**2.0))))--cos(1.0)--cos(0.0)**3.0)) +# print(parse_brackets.parse_brackets('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) +# print(calculate_math_parameters.calculate_math_parameters('e + .3 + e ')) +# print(pcalc('7+((4+e) + log(8)*8)/cos((log(8) - 4)*2)')) + +def calculate(value): + parameters_level_one = ['**'] + parameters_level_two = ['/', '*', '//', '%'] + parameters_level_three = ['+', '-'] + all_parameters = parameters_level_one + parameters_level_two + parameters_level_three + # get_numbers = [] + # get_operators = [] + # temp = "" + # prev_item = "" + # value = value.replace(' ', '') + # for item in value: + # if re.match(r'\d', item): + # get_number.append('item') + # if not re.match(r'\d]', item): + operators = re.findall(r'(\D*[^.?\d?])', value) + digits = re.findall(r'(\.*\d+\.*\d*)', value) + counter = 0 + get_first_number = 0 + get_second_number = 0 + for item in operators: + item = item.replace(' ', '') + if len(digits) > counter: + get_first_number = digits[counter] + if len(digits) > counter + 1: + get_second_number = digits[counter + 1] + if item not in all_parameters: + minus = re.findall('-', item) + + elements = re.findall(r'[^-+\s]', item) + print(len(minus) % 2) + if len(minus) % 2 == 0: + get_second_number = '-' + get_second_number + print('elements:', elements) + if len(minus) == 0: + return "Error: not accessible operator '" + item + "'" + get_parameter = re.findall(r'(\D*[^-+.?\d?])', value) + counter += 1 + print(get_first_number) + print(get_second_number) + print('result:', float(get_first_number) * float(get_second_number)) + + + print(operators) + print(digits) + + + +# print(calculate('84**7/4**7++-++--+-1 - 4 + 7')) +# print(calculate('3 + 2 / 3 -2')) +# print(2 * ---+--3) +# print(1---++++--1) diff --git a/final_task/pycalc_common.py b/final_task/pycalc_common.py new file mode 100644 index 00000000..c88cd192 --- /dev/null +++ b/final_task/pycalc_common.py @@ -0,0 +1,20 @@ +import re +import calculate_math_parameters +import parse_brackets +import calculate_expression +import math + +def pcalc(value): + value = value.replace('pi', str(math.pi)).replace('e', str(math.e)) + left_bracket = re.findall(r'\(', value) + right_bracket = re.findall(r'\)', value) + if len(left_bracket) != len(right_bracket): + return 'error: missing bracket' + + math_parameters_from_expression = re.findall(r'(\w+)\s*\((.+)\)', value) + result = value + if len( math_parameters_from_expression): + result = "".join(calculate_math_parameters.calc_math_parameter(value)) + result = parse_brackets.parse_brackets(result) + result = calculate_expression.calculate(result) + return result From ef9dd3972236b2c34a793033f9806365230d94bc Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 08:02:36 +0300 Subject: [PATCH 02/17] create setup --- final_task/setup.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/final_task/setup.py b/final_task/setup.py index e69de29b..c2da5872 100644 --- a/final_task/setup.py +++ b/final_task/setup.py @@ -0,0 +1,21 @@ +import setuptools +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name='pycalc', + version='1.0', + scripts=['pycalc'], + author="Maxim Tsyba", + author_email="maksimtsuba@gmail.com", + description="Calculator for EPAM", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/javatechy/dokr", + packages=setuptools.find_packages(), + classifiers=[ + "Programming Language :: Python :: 3.6", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + ) \ No newline at end of file From 373349fe4a480f859318471acb437c54d55b87fa Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 08:15:56 +0300 Subject: [PATCH 03/17] fix setup --- final_task/calculate_expression.py | 5 +++-- final_task/setup.py | 34 ++++++++++++++++-------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/final_task/calculate_expression.py b/final_task/calculate_expression.py index d69c3d14..b0acda10 100644 --- a/final_task/calculate_expression.py +++ b/final_task/calculate_expression.py @@ -29,7 +29,8 @@ def calculate(value): for operator in operators: format_operator = operator.replace(' ', '') - if format_operator == '/' or format_operator == '*' or format_operator == '//' or format_operator == '%' or format_operator == '**': + if format_operator == '/' or format_operator == '*' or format_operator == '//' or format_operator == '%' \ + or format_operator == '**': first_parameter = digits[counter] if check: first_parameter = rest_digits[-1] @@ -73,4 +74,4 @@ def calculate(value): elif format_operator == '-': result = arithmetic.subtraction(result, rest_digits[counter2 + 1]) counter2 += 1 - return result \ No newline at end of file + return result diff --git a/final_task/setup.py b/final_task/setup.py index c2da5872..ed67b206 100644 --- a/final_task/setup.py +++ b/final_task/setup.py @@ -1,21 +1,23 @@ import setuptools + with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( - name='pycalc', - version='1.0', - scripts=['pycalc'], - author="Maxim Tsyba", - author_email="maksimtsuba@gmail.com", - description="Calculator for EPAM", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/javatechy/dokr", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 3.6", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], - ) \ No newline at end of file + name='pycalc', + version='1.0', + + author="Maxim Tsyba", + author_email="maksimtsuba@gmail.com", + description="Calculator for EPAM", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/javatechy/dokr", + packages=setuptools.find_packages(), + py_modules=["pycalc"], + classifiers=[ + "Programming Language :: Python :: 3.6", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], +) From cf87a922379cfd10f7343dbf0f4c00572ea2a967 Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 08:35:34 +0300 Subject: [PATCH 04/17] corrected code style --- final_task/calculate_math_parameters.py | 1 - final_task/pycalc.py | 8 -------- final_task/pycalc_common.py | 3 ++- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/final_task/calculate_math_parameters.py b/final_task/calculate_math_parameters.py index fa13290d..06bae4e7 100644 --- a/final_task/calculate_math_parameters.py +++ b/final_task/calculate_math_parameters.py @@ -81,4 +81,3 @@ def calc_math_parameter(value): temp = "" previous_element = item return result - diff --git a/final_task/pycalc.py b/final_task/pycalc.py index 2985b150..08a37dd9 100644 --- a/final_task/pycalc.py +++ b/final_task/pycalc.py @@ -83,13 +83,5 @@ def calculate(value): print(get_second_number) print('result:', float(get_first_number) * float(get_second_number)) - print(operators) print(digits) - - - -# print(calculate('84**7/4**7++-++--+-1 - 4 + 7')) -# print(calculate('3 + 2 / 3 -2')) -# print(2 * ---+--3) -# print(1---++++--1) diff --git a/final_task/pycalc_common.py b/final_task/pycalc_common.py index c88cd192..f65758bb 100644 --- a/final_task/pycalc_common.py +++ b/final_task/pycalc_common.py @@ -4,6 +4,7 @@ import calculate_expression import math + def pcalc(value): value = value.replace('pi', str(math.pi)).replace('e', str(math.e)) left_bracket = re.findall(r'\(', value) @@ -13,7 +14,7 @@ def pcalc(value): math_parameters_from_expression = re.findall(r'(\w+)\s*\((.+)\)', value) result = value - if len( math_parameters_from_expression): + if len(math_parameters_from_expression): result = "".join(calculate_math_parameters.calc_math_parameter(value)) result = parse_brackets.parse_brackets(result) result = calculate_expression.calculate(result) From 999ed8b5580afa41c91aa611cda9dc38dea6e088 Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 08:42:58 +0300 Subject: [PATCH 05/17] fix setup --- final_task/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/final_task/setup.py b/final_task/setup.py index ed67b206..a70b95e1 100644 --- a/final_task/setup.py +++ b/final_task/setup.py @@ -14,6 +14,7 @@ long_description_content_type="text/markdown", url="https://github.com/javatechy/dokr", packages=setuptools.find_packages(), + entry_points={'console_scripts': ['pycalc = pycalc:main']}, py_modules=["pycalc"], classifiers=[ "Programming Language :: Python :: 3.6", From f22e808be99dfbd3e6b82d49588e27943e57a4dc Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 08:48:08 +0300 Subject: [PATCH 06/17] move file --- final_task/arithmetic.py => arithmetic.py | 0 final_task/calculate_expression.py => calculate_expression.py | 0 .../calculate_math_parameters.py => calculate_math_parameters.py | 0 final_task/parse_brackets.py => parse_brackets.py | 0 final_task/pycalc_common.py => pycalc_common.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename final_task/arithmetic.py => arithmetic.py (100%) rename final_task/calculate_expression.py => calculate_expression.py (100%) rename final_task/calculate_math_parameters.py => calculate_math_parameters.py (100%) rename final_task/parse_brackets.py => parse_brackets.py (100%) rename final_task/pycalc_common.py => pycalc_common.py (100%) diff --git a/final_task/arithmetic.py b/arithmetic.py similarity index 100% rename from final_task/arithmetic.py rename to arithmetic.py diff --git a/final_task/calculate_expression.py b/calculate_expression.py similarity index 100% rename from final_task/calculate_expression.py rename to calculate_expression.py diff --git a/final_task/calculate_math_parameters.py b/calculate_math_parameters.py similarity index 100% rename from final_task/calculate_math_parameters.py rename to calculate_math_parameters.py diff --git a/final_task/parse_brackets.py b/parse_brackets.py similarity index 100% rename from final_task/parse_brackets.py rename to parse_brackets.py diff --git a/final_task/pycalc_common.py b/pycalc_common.py similarity index 100% rename from final_task/pycalc_common.py rename to pycalc_common.py From 9cd106210c3592c3eaddfce4f9a3cbaddb2afe25 Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 09:04:25 +0300 Subject: [PATCH 07/17] correct imports --- arithmetic.py => final_task/arithmetic.py | 0 calculate_expression.py => final_task/calculate_expression.py | 3 +-- .../calculate_math_parameters.py | 3 +-- parse_brackets.py => final_task/parse_brackets.py | 3 +-- final_task/pycalc.py | 3 ++- pycalc_common.py => final_task/pycalc_common.py | 4 +--- 6 files changed, 6 insertions(+), 10 deletions(-) rename arithmetic.py => final_task/arithmetic.py (100%) rename calculate_expression.py => final_task/calculate_expression.py (98%) rename calculate_math_parameters.py => final_task/calculate_math_parameters.py (98%) rename parse_brackets.py => final_task/parse_brackets.py (97%) rename pycalc_common.py => final_task/pycalc_common.py (87%) diff --git a/arithmetic.py b/final_task/arithmetic.py similarity index 100% rename from arithmetic.py rename to final_task/arithmetic.py diff --git a/calculate_expression.py b/final_task/calculate_expression.py similarity index 98% rename from calculate_expression.py rename to final_task/calculate_expression.py index b0acda10..c88793ee 100644 --- a/calculate_expression.py +++ b/final_task/calculate_expression.py @@ -1,6 +1,5 @@ -import arithmetic +from final_task import arithmetic import re -import math def calculate(value): diff --git a/calculate_math_parameters.py b/final_task/calculate_math_parameters.py similarity index 98% rename from calculate_math_parameters.py rename to final_task/calculate_math_parameters.py index 06bae4e7..1856c19f 100644 --- a/calculate_math_parameters.py +++ b/final_task/calculate_math_parameters.py @@ -1,8 +1,7 @@ import math import re import builtins -import calculate_expression -import parse_brackets +from final_task import calculate_expression, parse_brackets math_param = dir(math) additional_param = ['abs', 'round'] diff --git a/parse_brackets.py b/final_task/parse_brackets.py similarity index 97% rename from parse_brackets.py rename to final_task/parse_brackets.py index 9e3b99f4..a4537653 100644 --- a/parse_brackets.py +++ b/final_task/parse_brackets.py @@ -1,5 +1,4 @@ -import math -import calculate_expression +from final_task import calculate_expression def parse_brackets(value): diff --git a/final_task/pycalc.py b/final_task/pycalc.py index 08a37dd9..b0f774c0 100644 --- a/final_task/pycalc.py +++ b/final_task/pycalc.py @@ -1,6 +1,7 @@ import argparse import re -import pycalc_common +from final_task import pycalc_common + # from math import * parser = argparse.ArgumentParser() diff --git a/pycalc_common.py b/final_task/pycalc_common.py similarity index 87% rename from pycalc_common.py rename to final_task/pycalc_common.py index f65758bb..5fa4ac73 100644 --- a/pycalc_common.py +++ b/final_task/pycalc_common.py @@ -1,7 +1,5 @@ import re -import calculate_math_parameters -import parse_brackets -import calculate_expression +from final_task import calculate_math_parameters, calculate_expression, parse_brackets import math From db5a3bab003dcf0087fec57f66804141fb09104e Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 09:07:42 +0300 Subject: [PATCH 08/17] correct imports --- final_task/pycalc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/final_task/pycalc.py b/final_task/pycalc.py index b0f774c0..6de8fa7e 100644 --- a/final_task/pycalc.py +++ b/final_task/pycalc.py @@ -1,6 +1,6 @@ import argparse import re -from final_task import pycalc_common +from . import pycalc_common # from math import * From eb95956babc217dac1d4d8fd7ba8378cada656fa Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 09:11:30 +0300 Subject: [PATCH 09/17] correct return result --- final_task/pycalc.py | 17 +++++++++-------- final_task/pycalc_common.py | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/final_task/pycalc.py b/final_task/pycalc.py index 6de8fa7e..8ff4277b 100644 --- a/final_task/pycalc.py +++ b/final_task/pycalc.py @@ -1,16 +1,17 @@ import argparse import re -from . import pycalc_common +from final_task import pycalc_common # from math import * +# +# parser = argparse.ArgumentParser() +# parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") +# parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") +# args = parser.parse_args() +# if args.EXPRESSION: +# print(pycalc_common.pcalc(args.EXPRESSION)) -parser = argparse.ArgumentParser() -parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") -parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") -args = parser.parse_args() -if args.EXPRESSION: - print(pycalc_common.pcalc(args.EXPRESSION)) - +print(type(pycalc_common.pcalc('-13'))) # print(pycalc_common.pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) # def pcalc(value): # left_bracket = re.findall(r'\(', value) diff --git a/final_task/pycalc_common.py b/final_task/pycalc_common.py index 5fa4ac73..cc892682 100644 --- a/final_task/pycalc_common.py +++ b/final_task/pycalc_common.py @@ -16,4 +16,4 @@ def pcalc(value): result = "".join(calculate_math_parameters.calc_math_parameter(value)) result = parse_brackets.parse_brackets(result) result = calculate_expression.calculate(result) - return result + return float(result) From 8764329f57405ccb69d07a768c7779168df9c99e Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 09:13:13 +0300 Subject: [PATCH 10/17] correct argparse --- final_task/pycalc.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/final_task/pycalc.py b/final_task/pycalc.py index 8ff4277b..d4040ff4 100644 --- a/final_task/pycalc.py +++ b/final_task/pycalc.py @@ -2,16 +2,16 @@ import re from final_task import pycalc_common -# from math import * -# -# parser = argparse.ArgumentParser() -# parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") -# parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") -# args = parser.parse_args() -# if args.EXPRESSION: -# print(pycalc_common.pcalc(args.EXPRESSION)) +from math import * + +parser = argparse.ArgumentParser() +parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") +parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") +args = parser.parse_args() +if args.EXPRESSION: + print(pycalc_common.pcalc(args.EXPRESSION)) -print(type(pycalc_common.pcalc('-13'))) +# print(type(pycalc_common.pcalc('-13'))) # print(pycalc_common.pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) # def pcalc(value): # left_bracket = re.findall(r'\(', value) From 82466b63ef3ef7c97d5a0358f1d213e7348882c6 Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 09:18:33 +0300 Subject: [PATCH 11/17] try fix imports --- final_task/additional_func/__init__.py | 0 final_task/{ => additional_func}/pycalc_common.py | 2 +- final_task/calculate_expression.py | 2 +- final_task/calculate_math_parameters.py | 2 +- final_task/parse_brackets.py | 2 +- final_task/pycalc.py | 4 +--- 6 files changed, 5 insertions(+), 7 deletions(-) create mode 100644 final_task/additional_func/__init__.py rename final_task/{ => additional_func}/pycalc_common.py (88%) diff --git a/final_task/additional_func/__init__.py b/final_task/additional_func/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/final_task/pycalc_common.py b/final_task/additional_func/pycalc_common.py similarity index 88% rename from final_task/pycalc_common.py rename to final_task/additional_func/pycalc_common.py index cc892682..8bf7fb37 100644 --- a/final_task/pycalc_common.py +++ b/final_task/additional_func/pycalc_common.py @@ -1,5 +1,5 @@ import re -from final_task import calculate_math_parameters, calculate_expression, parse_brackets +import calculate_math_parameters, calculate_expression, parse_brackets import math diff --git a/final_task/calculate_expression.py b/final_task/calculate_expression.py index c88793ee..9ffb8383 100644 --- a/final_task/calculate_expression.py +++ b/final_task/calculate_expression.py @@ -1,4 +1,4 @@ -from final_task import arithmetic +import arithmetic import re diff --git a/final_task/calculate_math_parameters.py b/final_task/calculate_math_parameters.py index 1856c19f..7d5c914a 100644 --- a/final_task/calculate_math_parameters.py +++ b/final_task/calculate_math_parameters.py @@ -1,7 +1,7 @@ import math import re import builtins -from final_task import calculate_expression, parse_brackets +import calculate_expression, parse_brackets math_param = dir(math) additional_param = ['abs', 'round'] diff --git a/final_task/parse_brackets.py b/final_task/parse_brackets.py index a4537653..74223171 100644 --- a/final_task/parse_brackets.py +++ b/final_task/parse_brackets.py @@ -1,4 +1,4 @@ -from final_task import calculate_expression +import calculate_expression def parse_brackets(value): diff --git a/final_task/pycalc.py b/final_task/pycalc.py index d4040ff4..c765f1d2 100644 --- a/final_task/pycalc.py +++ b/final_task/pycalc.py @@ -1,8 +1,6 @@ import argparse import re -from final_task import pycalc_common - -from math import * +from additional_func import pycalc_common parser = argparse.ArgumentParser() parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") From cf7632f6a5b190f7ebd7dbdd8e2971b538f30304 Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 09:24:27 +0300 Subject: [PATCH 12/17] try fix imports --- final_task/additional_func/__init__.py | 0 final_task/{ => additional_func}/arithmetic.py | 0 final_task/{ => additional_func}/calculate_expression.py | 2 +- final_task/{ => additional_func}/calculate_math_parameters.py | 2 +- final_task/{ => additional_func}/parse_brackets.py | 2 +- final_task/additional_func/pycalc_common.py | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 final_task/additional_func/__init__.py rename final_task/{ => additional_func}/arithmetic.py (100%) rename final_task/{ => additional_func}/calculate_expression.py (98%) rename final_task/{ => additional_func}/calculate_math_parameters.py (97%) rename final_task/{ => additional_func}/parse_brackets.py (96%) diff --git a/final_task/additional_func/__init__.py b/final_task/additional_func/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/final_task/arithmetic.py b/final_task/additional_func/arithmetic.py similarity index 100% rename from final_task/arithmetic.py rename to final_task/additional_func/arithmetic.py diff --git a/final_task/calculate_expression.py b/final_task/additional_func/calculate_expression.py similarity index 98% rename from final_task/calculate_expression.py rename to final_task/additional_func/calculate_expression.py index 9ffb8383..9391f383 100644 --- a/final_task/calculate_expression.py +++ b/final_task/additional_func/calculate_expression.py @@ -1,4 +1,4 @@ -import arithmetic +from additional_func import arithmetic import re diff --git a/final_task/calculate_math_parameters.py b/final_task/additional_func/calculate_math_parameters.py similarity index 97% rename from final_task/calculate_math_parameters.py rename to final_task/additional_func/calculate_math_parameters.py index 7d5c914a..0588a9dd 100644 --- a/final_task/calculate_math_parameters.py +++ b/final_task/additional_func/calculate_math_parameters.py @@ -1,7 +1,7 @@ import math import re import builtins -import calculate_expression, parse_brackets +from additional_func import calculate_expression, parse_brackets math_param = dir(math) additional_param = ['abs', 'round'] diff --git a/final_task/parse_brackets.py b/final_task/additional_func/parse_brackets.py similarity index 96% rename from final_task/parse_brackets.py rename to final_task/additional_func/parse_brackets.py index 74223171..07fd3b22 100644 --- a/final_task/parse_brackets.py +++ b/final_task/additional_func/parse_brackets.py @@ -1,4 +1,4 @@ -import calculate_expression +from additional_func import calculate_expression def parse_brackets(value): diff --git a/final_task/additional_func/pycalc_common.py b/final_task/additional_func/pycalc_common.py index 8bf7fb37..28393157 100644 --- a/final_task/additional_func/pycalc_common.py +++ b/final_task/additional_func/pycalc_common.py @@ -1,5 +1,5 @@ import re -import calculate_math_parameters, calculate_expression, parse_brackets +from additional_func import calculate_math_parameters, calculate_expression, parse_brackets import math From 37c39e441b4cb164efe263f48558003cff513556 Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 09:29:33 +0300 Subject: [PATCH 13/17] try fix imports --- final_task/additional_func/pycalc_common.py | 4 ++-- final_task/pycalc.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/final_task/additional_func/pycalc_common.py b/final_task/additional_func/pycalc_common.py index 28393157..e4fe78e3 100644 --- a/final_task/additional_func/pycalc_common.py +++ b/final_task/additional_func/pycalc_common.py @@ -1,5 +1,5 @@ import re -from additional_func import calculate_math_parameters, calculate_expression, parse_brackets +from .additional_func import calculate_math_parameters, calculate_expression, parse_brackets import math @@ -16,4 +16,4 @@ def pcalc(value): result = "".join(calculate_math_parameters.calc_math_parameter(value)) result = parse_brackets.parse_brackets(result) result = calculate_expression.calculate(result) - return float(result) + return int(result) diff --git a/final_task/pycalc.py b/final_task/pycalc.py index c765f1d2..a9d203fa 100644 --- a/final_task/pycalc.py +++ b/final_task/pycalc.py @@ -1,6 +1,6 @@ import argparse import re -from additional_func import pycalc_common +from .additional_func import pycalc_common parser = argparse.ArgumentParser() parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") From e0600944f2cb48ba36d62f9a40780ef5d88bd793 Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 09:43:19 +0300 Subject: [PATCH 14/17] try fix imports --- final_task/pycalc.py | 4 ++-- final_task/{additional_func => }/pycalc_common.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename final_task/{additional_func => }/pycalc_common.py (84%) diff --git a/final_task/pycalc.py b/final_task/pycalc.py index a9d203fa..73f8635f 100644 --- a/final_task/pycalc.py +++ b/final_task/pycalc.py @@ -1,13 +1,13 @@ import argparse import re -from .additional_func import pycalc_common +from pycalc_common import pcalc parser = argparse.ArgumentParser() parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") args = parser.parse_args() if args.EXPRESSION: - print(pycalc_common.pcalc(args.EXPRESSION)) + print(pcalc(args.EXPRESSION)) # print(type(pycalc_common.pcalc('-13'))) # print(pycalc_common.pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) diff --git a/final_task/additional_func/pycalc_common.py b/final_task/pycalc_common.py similarity index 84% rename from final_task/additional_func/pycalc_common.py rename to final_task/pycalc_common.py index e4fe78e3..28393157 100644 --- a/final_task/additional_func/pycalc_common.py +++ b/final_task/pycalc_common.py @@ -1,5 +1,5 @@ import re -from .additional_func import calculate_math_parameters, calculate_expression, parse_brackets +from additional_func import calculate_math_parameters, calculate_expression, parse_brackets import math @@ -16,4 +16,4 @@ def pcalc(value): result = "".join(calculate_math_parameters.calc_math_parameter(value)) result = parse_brackets.parse_brackets(result) result = calculate_expression.calculate(result) - return int(result) + return float(result) From f54ff26f67d06c66679fdfe7ccb3351ca8d6ba8b Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 10:40:02 +0300 Subject: [PATCH 15/17] correct setup.py --- final_task/pycalc.py | 87 ------------------ final_task/pycalc/__init__.py | 0 .../{additional_func => pycalc}/arithmetic.py | 0 .../calculate_expression.py | 2 +- .../calculate_math_parameters.py | 2 +- .../parse_brackets.py | 2 +- final_task/pycalc/pycalc.py | 90 +++++++++++++++++++ final_task/{ => pycalc}/pycalc_common.py | 2 +- final_task/setup.py | 6 +- 9 files changed, 97 insertions(+), 94 deletions(-) delete mode 100644 final_task/pycalc.py create mode 100644 final_task/pycalc/__init__.py rename final_task/{additional_func => pycalc}/arithmetic.py (100%) rename final_task/{additional_func => pycalc}/calculate_expression.py (98%) rename final_task/{additional_func => pycalc}/calculate_math_parameters.py (97%) rename final_task/{additional_func => pycalc}/parse_brackets.py (96%) create mode 100644 final_task/pycalc/pycalc.py rename final_task/{ => pycalc}/pycalc_common.py (87%) diff --git a/final_task/pycalc.py b/final_task/pycalc.py deleted file mode 100644 index 73f8635f..00000000 --- a/final_task/pycalc.py +++ /dev/null @@ -1,87 +0,0 @@ -import argparse -import re -from pycalc_common import pcalc - -parser = argparse.ArgumentParser() -parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") -parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") -args = parser.parse_args() -if args.EXPRESSION: - print(pcalc(args.EXPRESSION)) - -# print(type(pycalc_common.pcalc('-13'))) -# print(pycalc_common.pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) -# def pcalc(value): -# left_bracket = re.findall(r'\(', value) -# right_bracket = re.findall(r'\)', value) -# if len(left_bracket) != len(right_bracket): -# return 'error: missing bracket' -# -# result_calculate = calculate_math_parameters.calculate_math_parameters(value) -# -# print('result_calculate', result_calculate) -# if len(left_bracket) or len(right_bracket): -# result = parse_brackets.parse_brackets(result_calculate) -# else: -# result = eval(value) -# # print('eval_result:', eval(value)) -# print('my_result:', result) -# return result - - -# print(pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) -# print(sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))) -# print(calculate_expression.calculate('2.718281828459045**2.718281828459045**-0.8462204041751706')) -# print(2.718281828459045**2.718281828459045**-0.8462204041751706) -# print(2.718281828459045**-0.8462204041751706) -# print(2.718281828459045**0.4290334443756452) -# print(calculate_expression.calculate('5**2')) -# print(calc_math('sin(-cos(-sin(3.0)-cos(-sin(-3.0*5.0)-sin(cos(log10(43.0))))+cos(sin(sin(34.0-2.0**2.0))))--cos(1.0)--cos(0.0)**3.0)')) -# print(sin(-cos(-sin(3.0)-cos(-sin(-3.0*5.0)-sin(cos(log10(43.0))))+cos(sin(sin(34.0-2.0**2.0))))--cos(1.0)--cos(0.0)**3.0)) -# print(parse_brackets.parse_brackets('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) -# print(calculate_math_parameters.calculate_math_parameters('e + .3 + e ')) -# print(pcalc('7+((4+e) + log(8)*8)/cos((log(8) - 4)*2)')) - -def calculate(value): - parameters_level_one = ['**'] - parameters_level_two = ['/', '*', '//', '%'] - parameters_level_three = ['+', '-'] - all_parameters = parameters_level_one + parameters_level_two + parameters_level_three - # get_numbers = [] - # get_operators = [] - # temp = "" - # prev_item = "" - # value = value.replace(' ', '') - # for item in value: - # if re.match(r'\d', item): - # get_number.append('item') - # if not re.match(r'\d]', item): - operators = re.findall(r'(\D*[^.?\d?])', value) - digits = re.findall(r'(\.*\d+\.*\d*)', value) - counter = 0 - get_first_number = 0 - get_second_number = 0 - for item in operators: - item = item.replace(' ', '') - if len(digits) > counter: - get_first_number = digits[counter] - if len(digits) > counter + 1: - get_second_number = digits[counter + 1] - if item not in all_parameters: - minus = re.findall('-', item) - - elements = re.findall(r'[^-+\s]', item) - print(len(minus) % 2) - if len(minus) % 2 == 0: - get_second_number = '-' + get_second_number - print('elements:', elements) - if len(minus) == 0: - return "Error: not accessible operator '" + item + "'" - get_parameter = re.findall(r'(\D*[^-+.?\d?])', value) - counter += 1 - print(get_first_number) - print(get_second_number) - print('result:', float(get_first_number) * float(get_second_number)) - - print(operators) - print(digits) diff --git a/final_task/pycalc/__init__.py b/final_task/pycalc/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/final_task/additional_func/arithmetic.py b/final_task/pycalc/arithmetic.py similarity index 100% rename from final_task/additional_func/arithmetic.py rename to final_task/pycalc/arithmetic.py diff --git a/final_task/additional_func/calculate_expression.py b/final_task/pycalc/calculate_expression.py similarity index 98% rename from final_task/additional_func/calculate_expression.py rename to final_task/pycalc/calculate_expression.py index 9391f383..51b10bab 100644 --- a/final_task/additional_func/calculate_expression.py +++ b/final_task/pycalc/calculate_expression.py @@ -1,4 +1,4 @@ -from additional_func import arithmetic +from pycalc import arithmetic import re diff --git a/final_task/additional_func/calculate_math_parameters.py b/final_task/pycalc/calculate_math_parameters.py similarity index 97% rename from final_task/additional_func/calculate_math_parameters.py rename to final_task/pycalc/calculate_math_parameters.py index 0588a9dd..608ac695 100644 --- a/final_task/additional_func/calculate_math_parameters.py +++ b/final_task/pycalc/calculate_math_parameters.py @@ -1,7 +1,7 @@ import math import re import builtins -from additional_func import calculate_expression, parse_brackets +from pycalc import calculate_expression, parse_brackets math_param = dir(math) additional_param = ['abs', 'round'] diff --git a/final_task/additional_func/parse_brackets.py b/final_task/pycalc/parse_brackets.py similarity index 96% rename from final_task/additional_func/parse_brackets.py rename to final_task/pycalc/parse_brackets.py index 07fd3b22..2ad0a1d0 100644 --- a/final_task/additional_func/parse_brackets.py +++ b/final_task/pycalc/parse_brackets.py @@ -1,4 +1,4 @@ -from additional_func import calculate_expression +from pycalc import calculate_expression def parse_brackets(value): diff --git a/final_task/pycalc/pycalc.py b/final_task/pycalc/pycalc.py new file mode 100644 index 00000000..8354c4c8 --- /dev/null +++ b/final_task/pycalc/pycalc.py @@ -0,0 +1,90 @@ +import argparse +# import re +from pycalc.pycalc_common import pcalc + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("EXPRESSION", type=str, help="expression is the string you use here") + parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") + args = parser.parse_args() + if args.EXPRESSION: + return pcalc(args.EXPRESSION) + +# print(pcalc('round(123.4567890)')) +# print(type(pycalc_common.pcalc('-13'))) +# print(pycalc_common.pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) +# def pcalc(value): +# left_bracket = re.findall(r'\(', value) +# right_bracket = re.findall(r'\)', value) +# if len(left_bracket) != len(right_bracket): +# return 'error: missing bracket' +# +# result_calculate = calculate_math_parameters.calculate_math_parameters(value) +# +# print('result_calculate', result_calculate) +# if len(left_bracket) or len(right_bracket): +# result = parse_brackets.parse_brackets(result_calculate) +# else: +# result = eval(value) +# # print('eval_result:', eval(value)) +# print('my_result:', result) +# return result + + +# print(pcalc('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) +# print(sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))) +# print(calculate_expression.calculate('2.718281828459045**2.718281828459045**-0.8462204041751706')) +# print(2.718281828459045**2.718281828459045**-0.8462204041751706) +# print(2.718281828459045**-0.8462204041751706) +# print(2.718281828459045**0.4290334443756452) +# print(calculate_expression.calculate('5**2')) +# print(calc_math('sin(-cos(-sin(3.0)-cos(-sin(-3.0*5.0)-sin(cos(log10(43.0))))+cos(sin(sin(34.0-2.0**2.0))))--cos(1.0)--cos(0.0)**3.0)')) +# print(sin(-cos(-sin(3.0)-cos(-sin(-3.0*5.0)-sin(cos(log10(43.0))))+cos(sin(sin(34.0-2.0**2.0))))--cos(1.0)--cos(0.0)**3.0)) +# print(parse_brackets.parse_brackets('sin(e**log(e**e**sin(23.0),45.0) + cos(3.0+log10(e**-e)))')) +# print(calculate_math_parameters.calculate_math_parameters('e + .3 + e ')) +# print(pcalc('7+((4+e) + log(8)*8)/cos((log(8) - 4)*2)')) +# +# def calculate(value): +# parameters_level_one = ['**'] +# parameters_level_two = ['/', '*', '//', '%'] +# parameters_level_three = ['+', '-'] +# all_parameters = parameters_level_one + parameters_level_two + parameters_level_three +# # get_numbers = [] +# # get_operators = [] +# # temp = "" +# # prev_item = "" +# # value = value.replace(' ', '') +# # for item in value: +# # if re.match(r'\d', item): +# # get_number.append('item') +# # if not re.match(r'\d]', item): +# operators = re.findall(r'(\D*[^.?\d?])', value) +# digits = re.findall(r'(\.*\d+\.*\d*)', value) +# counter = 0 +# get_first_number = 0 +# get_second_number = 0 +# for item in operators: +# item = item.replace(' ', '') +# if len(digits) > counter: +# get_first_number = digits[counter] +# if len(digits) > counter + 1: +# get_second_number = digits[counter + 1] +# if item not in all_parameters: +# minus = re.findall('-', item) +# +# elements = re.findall(r'[^-+\s]', item) +# print(len(minus) % 2) +# if len(minus) % 2 == 0: +# get_second_number = '-' + get_second_number +# print('elements:', elements) +# if len(minus) == 0: +# return "Error: not accessible operator '" + item + "'" +# get_parameter = re.findall(r'(\D*[^-+.?\d?])', value) +# counter += 1 +# print(get_first_number) +# print(get_second_number) +# print('result:', float(get_first_number) * float(get_second_number)) +# +# print(operators) +# print(digits) diff --git a/final_task/pycalc_common.py b/final_task/pycalc/pycalc_common.py similarity index 87% rename from final_task/pycalc_common.py rename to final_task/pycalc/pycalc_common.py index 28393157..6e62a9f7 100644 --- a/final_task/pycalc_common.py +++ b/final_task/pycalc/pycalc_common.py @@ -1,5 +1,5 @@ import re -from additional_func import calculate_math_parameters, calculate_expression, parse_brackets +from pycalc import calculate_math_parameters, calculate_expression, parse_brackets import math diff --git a/final_task/setup.py b/final_task/setup.py index a70b95e1..c1375391 100644 --- a/final_task/setup.py +++ b/final_task/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name='pycalc', - version='1.0', + version='1.28', author="Maxim Tsyba", author_email="maksimtsuba@gmail.com", @@ -13,8 +13,8 @@ long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/javatechy/dokr", - packages=setuptools.find_packages(), - entry_points={'console_scripts': ['pycalc = pycalc:main']}, + packages=setuptools.find_packages(include=['pycalc']), + entry_points={'console_scripts': ['pycalc = pycalc.pycalc:main']}, py_modules=["pycalc"], classifiers=[ "Programming Language :: Python :: 3.6", From 99c07f604ac2e9e3189927c6f8deb43efe4eddda Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 10:43:31 +0300 Subject: [PATCH 16/17] correct result --- final_task/pycalc/pycalc_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/final_task/pycalc/pycalc_common.py b/final_task/pycalc/pycalc_common.py index 6e62a9f7..558c83d2 100644 --- a/final_task/pycalc/pycalc_common.py +++ b/final_task/pycalc/pycalc_common.py @@ -16,4 +16,4 @@ def pcalc(value): result = "".join(calculate_math_parameters.calc_math_parameter(value)) result = parse_brackets.parse_brackets(result) result = calculate_expression.calculate(result) - return float(result) + return int(result) From 4152ae2c3cefb0a51f3b5156a30b3c06b38765eb Mon Sep 17 00:00:00 2001 From: maximtsyba Date: Thu, 6 Jun 2019 11:00:02 +0300 Subject: [PATCH 17/17] correct result --- final_task/pycalc/pycalc.py | 2 +- final_task/pycalc/pycalc_common.py | 2 +- final_task/setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/final_task/pycalc/pycalc.py b/final_task/pycalc/pycalc.py index 8354c4c8..3e03fe3e 100644 --- a/final_task/pycalc/pycalc.py +++ b/final_task/pycalc/pycalc.py @@ -9,7 +9,7 @@ def main(): parser.add_argument("-m", "--use-modules", help="additional modules to use", action="store_true") args = parser.parse_args() if args.EXPRESSION: - return pcalc(args.EXPRESSION) + print(pcalc(args.EXPRESSION)) # print(pcalc('round(123.4567890)')) # print(type(pycalc_common.pcalc('-13'))) diff --git a/final_task/pycalc/pycalc_common.py b/final_task/pycalc/pycalc_common.py index 558c83d2..6e62a9f7 100644 --- a/final_task/pycalc/pycalc_common.py +++ b/final_task/pycalc/pycalc_common.py @@ -16,4 +16,4 @@ def pcalc(value): result = "".join(calculate_math_parameters.calc_math_parameter(value)) result = parse_brackets.parse_brackets(result) result = calculate_expression.calculate(result) - return int(result) + return float(result) diff --git a/final_task/setup.py b/final_task/setup.py index c1375391..7f9954c2 100644 --- a/final_task/setup.py +++ b/final_task/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name='pycalc', - version='1.28', + version='1.31', author="Maxim Tsyba", author_email="maksimtsuba@gmail.com",