Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .idea/PythonHomework.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

546 changes: 546 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions final_task/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import math
import operator
import string

LETTERS = tuple(string.ascii_lowercase + string.ascii_uppercase)
DIGITS = tuple(string.digits)

UNARY_OPERATORS = {'+': (1, operator.add),
'-': (1, operator.sub),
}

BINARY_OPERATORS = {'*': (2, operator.mul),
'/': (2, operator.truediv),
'//': (2, operator.floordiv),
'%': (2, operator.imod),
'^': (3, operator.ipow),
'<': (0, operator.lt),
'<=': (0, operator.le),
'>': (0, operator.gt),
'>=': (0, operator.ge),
'==': (0, operator.eq),
'!=': (0, operator.ne),
}

OPERATORS = UNARY_OPERATORS.copy()
OPERATORS.update(BINARY_OPERATORS)

PARENTHESES = ('(', ')')

OPERATORS_BEGIN = ('+', '-', '*', '/', '%', '^', '<', '>', '=', '!',)

DOUBLE_OPER_PART1 = ('/', '<', '>', '=', '!',)
DOUBLE_OPER_PART2 = ('/', '=',)

BUILT_IN_FUNCTIONS = ('abs', 'round')
NOT_SUPPORTED_MATH_FUNCTIONS = ('frexp', 'isclose', 'isinf', 'isfinite', 'isnan')
MATH_CONSTS = ('e', 'pi', 'inf', 'nan', 'tau')
MATH_FUNCTIONS = tuple([func for func in dir(math) if not func.startswith('_') and
func not in (MATH_CONSTS + NOT_SUPPORTED_MATH_FUNCTIONS)])

ALL_FUNCTIONS = BUILT_IN_FUNCTIONS + MATH_FUNCTIONS
ALL_FUNCTIONS_AND_CONSTS = ALL_FUNCTIONS + MATH_CONSTS

ALL_FUNCTIONS_DICT = {el: (4,) for el in ALL_FUNCTIONS}
ALL_FUNCTIONS_AND_OPERATORS_DICT = ALL_FUNCTIONS_DICT.copy()
ALL_FUNCTIONS_AND_OPERATORS_DICT.update(OPERATORS)


DELIMETERS = ('.', ',', ' ')
ALLOWED_TOKENS = OPERATORS_BEGIN + LETTERS + DIGITS + PARENTHESES + DELIMETERS
25 changes: 25 additions & 0 deletions final_task/pycalc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import argparse
from sys import argv

from pycalc_proc import PyCalcProcessing


def create_parser():
parser_ = argparse.ArgumentParser(prog='Py Calc',
description='Pure-python command-line calculator',
epilog='(c) Alina Laevskaya 2019.'
)

parser_.add_argument('EXPRESSION', type=str, help='String formula for processing.')
return parser_


def main():
parser = create_parser()
namespace = parser.parse_args(argv[1:])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем использовать sys.argv? ArgumentParser сам знает об аргументах командной строки.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Согласна. args = parser.parse_args()

py_calc_obj = PyCalcProcessing(namespace.EXPRESSION)
py_calc_obj.launch_processing()


if __name__ == '__main__':
main()
Loading