Skip to content

Commit ece3320

Browse files
implementation 11 corrections pip8 2
1 parent 2450724 commit ece3320

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

final_task/pycalc/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def createparser():
1616
"""Creates parser with one positional argument 'expression' to parse user's mathematical expression"""
1717
parser = argparse.ArgumentParser(prog='pycalc', description='pure Python command line calculator',
18-
epilog="""Anton Charnichenka for EPAM: Introduction to Python
18+
epilog="""Anton Charnichenka for EPAM: Introduction to Python
1919
and Golang programming, 2018.""")
2020
parser.add_argument('expression', help="""mathematical expression string to evaluate;
2121
implicit multiplication is supported""")

final_task/pycalc/pycalclib.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@
66

77

88
# r_strings that are used to find operators / functions / etc
9-
r_one_sign_operators = ['^\+', '^-', '^\*', '^/', '^\^', '^%']
10-
r_two_signs_operators = ['^//', '^\*\*']
11-
r_comparison_operators = ['^<=', '^>=', '^<', '^>', '^==', '^!=']
12-
r_functions = ['^acosh', '^acos', '^asinh', '^asin', '^atan2', '^atanh', '^atan', '^ceil', '^copysign', '^cosh',
13-
'^cos', '^degrees', '^erfc', '^erf', '^expm1', '^exp', '^fabs', '^factorial', '^floor', '^fmod',
14-
'^gamma', '^gcd', '^hypot', '^isfinite', '^isinf', '^isnan', '^ldexp', '^lgamma', '^log10', '^log1p',
15-
'^log2', '^log', '^pow', '^radians', '^sinh', '^sin', '^sqrt', '^tanh', '^tan', '^trunc',
16-
'^abs', '^round']
17-
r_negative_functions = ['^-acosh', '^-acos', '^-asinh', '^-asin', '^-atan2', '^-atanh', '^-atan', '^-ceil',
18-
'^-copysign', '^-cosh', '^-cos', '^-degrees', '^-erfc', '^-erf', '^-expm1', '^-exp',
19-
'^-fabs', '^-factorial', '^-floor', '^-fmod', '^-gamma', '^-gcd', '^-hypot', '^-isfinite',
20-
'^-isinf', '^-isnan', '^-ldexp', '^-lgamma', '^-log10', '^-log1p', '^-log2', '^-log',
21-
'^-pow', '^-radians', '^-sinh', '^-sin', '-^sqrt', '^-tanh', '^-tan', '^-trunc',
22-
'^-abs', '^-round']
23-
r_constants = ['^e', '^pi', '^tau', '^inf', '^nan']
24-
r_negative_constants = ['^\-e', '^\-pi', '^\-tau', '^\-inf', '^\-nan']
25-
r_int_numbers = ['^\d+']
26-
r_negative_int_numbers = ['^\-\d+']
27-
r_float_numbers = ['^\d+\.\d+|^\.\d+']
28-
r_negative_float_numbers = ['^\-\d+\.\d+|^\-\.\d+']
29-
r_brackets = ['^\(', '^\)']
30-
r_comma = ['^,']
31-
r_space = ['^\s']
9+
r_one_sign_operators = [r'^\+', r'^-', r'^\*', r'^/', r'^\^', r'^%']
10+
r_two_signs_operators = [r'^//', r'^\*\*']
11+
r_comparison_operators = [r'^<=', r'^>=', r'^<', r'^>', r'^==', r'^!=']
12+
r_functions = [r'^acosh', r'^acos', r'^asinh', r'^asin', r'^atan2', r'^atanh', r'^atan', r'^ceil', r'^copysign', r'^cosh',
13+
r'^cos', r'^degrees', r'^erfc', r'^erf', r'^expm1', r'^exp', r'^fabs', r'^factorial', r'^floor', r'^fmod',
14+
r'^gamma', r'^gcd', r'^hypot', r'^isfinite', r'^isinf', r'^isnan', r'^ldexp', r'^lgamma', r'^log10', r'^log1p',
15+
r'^log2', r'^log', r'^pow', r'^radians', r'^sinh', r'^sin', r'^sqrt', r'^tanh', r'^tan', r'^trunc',
16+
r'^abs', r'^round']
17+
r_negative_functions = [r'^-acosh', r'^-acos', r'^-asinh', r'^-asin', r'^-atan2', r'^-atanh', r'^-atan', r'^-ceil',
18+
r'^-copysign', r'^-cosh', r'^-cos', r'^-degrees', r'^-erfc', r'^-erf', r'^-expm1', r'^-exp',
19+
r'^-fabs', r'^-factorial', r'^-floor', r'^-fmod', r'^-gamma', r'^-gcd', r'^-hypot', r'^-isfinite',
20+
r'^-isinf', r'^-isnan', r'^-ldexp', r'^-lgamma', r'^-log10', r'^-log1p', r'^-log2', r'^-log',
21+
r'^-pow', r'^-radians', r'^-sinh', r'^-sin', r'-^sqrt', r'^-tanh', r'^-tan', r'^-trunc',
22+
r'^-abs', r'^-round']
23+
r_constants = [r'^e', r'^pi', r'^tau', r'^inf', r'^nan']
24+
r_negative_constants = [r'^\-e', r'^\-pi', r'^\-tau', r'^\-inf', r'^\-nan']
25+
r_int_numbers = [r'^\d+']
26+
r_negative_int_numbers = [r'^\-\d+']
27+
r_float_numbers = [r'^\d+\.\d+|^\.\d+']
28+
r_negative_float_numbers = [r'^\-\d+\.\d+|^\-\.\d+']
29+
r_brackets = [r'^\(', r'^\)']
30+
r_comma = [r'^,']
31+
r_space = [r'^\s']
3232
# all r_strings together
3333
r_strings = r_brackets + r_two_signs_operators + r_one_sign_operators + r_negative_functions + r_functions + \
3434
r_comparison_operators + r_negative_float_numbers + r_negative_int_numbers + r_negative_constants + \

final_task/pycalc/tokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def extract_tokens(self):
6262

6363
while len(self.user_expr) != 0:
6464
for r_string in self.r_strings:
65-
search_result = re.search(r''.join(r_string), self.user_expr)
65+
search_result = re.search(r_string, self.user_expr)
6666
if search_result is not None:
6767
if (search_result.group(0) == '-' and len(self.tokens) != 0
6868
and self.tokens[-1] in (['('] + self.operators[2:])):

0 commit comments

Comments
 (0)