E4IXGq)L=dHl|A31x!HV2)$LGH9ect;ny_NJbWBTCXb@!`$rE4avOWQnP
z{T>mD4|OG=drf(47VS_>v=Y7o3f@T{xf{wm^9=fOlT|>IC+w-n1>;7W1jKD|!&7^c
z+!1OX`vB%Uq0r+>(jCbloinaQf~#$c=?i(8UW9k~oSvJ#*;25}bUTHH6+zMqEA=E&uYCL5Xgolr1O6-Ge2;eT7FDb#op>K>t$3Kq@4RZqpAanDE0M1I@^Uo)}s
z{?BuZo`U?$*f2V`@~Z`ru3_6NYma4A;@U_aD
Date: Thu, 23 May 2019 01:37:25 +0300
Subject: [PATCH 29/73] Delete start.py
---
pycalc/start.py | 19 -------------------
1 file changed, 19 deletions(-)
delete mode 100644 pycalc/start.py
diff --git a/pycalc/start.py b/pycalc/start.py
deleted file mode 100644
index 847a6484..00000000
--- a/pycalc/start.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import argparse
-import pycalc.main as Main
-
-
-def main():
- parser = argparse.ArgumentParser(description="Pure-python command-line calculator")
- parser.add_argument("EXPRESSION", type=str, help='expression string to evaluate')
- parser.add_argument('-m MODULE[MODULE...]', '--use-modules MODULE[MODULE...]', nargs='*',
- help='additional modules to use', dest='modules', type=str, default=['math'])
- args = parser.parse_args()
-
- answer = Main.pycalc(args.EXPRESSION, args.modules)
- if type(answer) == float or type(answer) == int:
- if answer % 1 == 0:
- print(int(answer))
- else:
- print(answer)
- elif type(answer) == bool:
- print(answer)
From 51fc48c17febec274e91fc6c29e2bbee202376cb Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 01:37:35 +0300
Subject: [PATCH 30/73] Delete stack.py
---
pycalc/stack.py | 15 ---------------
1 file changed, 15 deletions(-)
delete mode 100644 pycalc/stack.py
diff --git a/pycalc/stack.py b/pycalc/stack.py
deleted file mode 100644
index 2ea6abbd..00000000
--- a/pycalc/stack.py
+++ /dev/null
@@ -1,15 +0,0 @@
-class Stack:
- def __init__(self):
- self.__items = []
-
- def is_empty(self):
- return self.__items == []
-
- def push(self, item):
- self.__items.append(item)
-
- def pop(self):
- return self.__items.pop()
-
- def size(self):
- return len(self.__items)
From 8d709650f165695308ca886fd725397c949258ad Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 01:37:45 +0300
Subject: [PATCH 31/73] Delete main.py
---
pycalc/main.py | 347 -------------------------------------------------
1 file changed, 347 deletions(-)
delete mode 100644 pycalc/main.py
diff --git a/pycalc/main.py b/pycalc/main.py
deleted file mode 100644
index 983e1c99..00000000
--- a/pycalc/main.py
+++ /dev/null
@@ -1,347 +0,0 @@
-import pycalc.stack as Stack
-import importlib
-import operator
-import math
-import re
-
-signs = ['+', '-', '*', '/', '^', '%', '>', '<', '=', '//', '!']
-
-logical_signs = {
- '>': operator.gt,
- '>=': operator.ge,
- '==': operator.eq,
- '!=': operator.ne,
- "<=": operator.le,
- "<": operator.le
-}
-
-
-operators_type1 = {
- '*': operator.mul,
- '/': operator.truediv,
- '//': operator.floordiv,
- '%': operator.mod
-}
-
-operators_main = {
- '+': operator.add,
- '-': operator.sub
-}
-
-math_consts = {
- "pi": math.pi,
- "e": math.e
-
-}
-
-functions = {'round': round, 'abs': abs}
-
-
-def get_args(expression):
- if len(expression) == 0:
- return ''
- expression.append(',')
- result = []
- prev = -1
- stack = Stack.Stack()
- for index, part in enumerate(expression):
- if part == ',' and stack.is_empty():
- result.append(float(calc(expression[prev + 1: index])))
- prev = index
- elif part == '(':
- stack.push(part)
- elif part == ')':
- stack.pop()
- return result
-
-
-def check_mistakes(expression):
- if len(expression) == 0:
- print("ERROR: empty expression")
- return False
- brackets_stack = Stack.Stack()
- for element in expression:
- if element == '(':
- brackets_stack.push('(')
- elif element == ')':
- if brackets_stack.is_empty():
- print("ERROR: brackets are not paired")
- return False
- brackets_stack.pop()
- if not brackets_stack.is_empty():
- print("ERROR: brackets are not paired")
- return False
- return True
-
-
-def separate(expression): # separates expression to logical parts
- new = ''
-
- for char in expression:
- if char != ' ':
- new += char
-
- expression = new
-
- def check_log10():
- nonlocal current
- nonlocal expression_list
- if current == '10' and expression_list[len(expression_list) - 1] == 'log':
- expression_list.pop()
- expression_list.append('log10')
- current = ''
-
- def fix_signs():
- nonlocal flag
- nonlocal current
- if flag == 'sign_main' and len(re.findall('-', current)) + len(re.findall("\+", current)) > 1:
- if (-1) ** len(re.findall('-', current)) < 0:
- current = '-'
- else:
- current = '+'
-
- def is_number(string):
- try:
- float(string)
- return True
- except ValueError:
- return False
-
- expression_list = []
- flag = "number"
- current = ''
- for char in expression:
- if char == ' ':
- flag = 'space'
- elif '0' <= char <= '9' or char == '.': # if part is number
- if flag == 'number': # if previously symbols were numbers
- current += char
- else: # if previously symbols weren't number
- if current != '':
- fix_signs()
- expression_list.append(current)
- current = ''
- flag = 'number'
- current += char
- elif 'a' <= char.lower() <= 'z':
- if flag == 'function': # if previously symbols were function
- current += char
- else: # if previously symbols weren't numbers
- if current != '':
- fix_signs()
- expression_list.append(current)
- current = ''
- flag = 'function'
- current += char
-
- elif char in operators_type1 or char == '^': # if previously symbols were sign
- if flag == 'sign_type1':
- current += char
- else: # if previously symbols weren't numbers
- if current != '':
- expression_list.append(current)
- current = ''
- flag = 'sign_type1'
- current += char
-
- elif char in signs: # if previously symbols were sign
- if flag == 'sign_main':
- current += char
- else: # if previously symbols weren't numbers
- if current != '':
- expression_list.append(current)
- current = ''
- flag = 'sign_main'
- current += char
-
- elif char in ['(', ')']:
- if current != '':
- check_log10()
- fix_signs()
- if current != '':
- expression_list.append(current)
- current = ''
- flag = 'bracket'
- expression_list.append(char)
- elif char == ',':
- if current != '':
- expression_list.append(current)
- current = ''
- flag = 'args'
- expression_list.append(char)
- if current != '':
- expression_list.append(current)
-
- index = 1
- while index <= len(expression_list) - 1:
- if expression_list[index] in operators_main and\
- (expression_list[index - 1] in operators_type1 or expression_list[index - 1] == '^') and\
- (is_number(expression_list[index + 1]) or expression_list[index + 1] in math_consts):
- expression_list[index + 1] = expression_list[index] + expression_list[index + 1]
- expression_list.pop(index)
- else:
- index += 1
- return expression_list
-
-
-def calc(expression):
- expression.append("/") # creating airbag
- expression.append("1")
- expression.append("+")
- expression.append("0")
-
- global functions # list of functions
- brackets = False # flag, if we are looking for brackets
- result = 0 # result variable
- main_number = '' # variable for number after + or -
- number = '' # variable for other numbers
- main_sign = '+' # sign before main number (default +)
- func = '' # variable for function
- sign = '' # sign before number
- previous_sign = '' # additionaly variable for sign
- stack = Stack.Stack() # stack for brackets
- power_stack = Stack.Stack() # stack for powered numbers
- no_numbers_flag = False
-
- for index, element in enumerate(expression):
- if brackets: # if in we find expression in brackets, we start searching of end bracket with stack
- if element == '(':
- stack.push('(')
- elif element == ')':
- stack.pop()
- if stack.is_empty():
- end = index
- if func != '': # if we find function
- temp = get_args(expression[begin + 1:end]) # getting arguments for func
- if temp != ['']:
- element = functions[func](*temp) # processing function with 1 or more args
- else:
- element = functions[func]() # processing function with no args
- func = ''
- else:
- element = float(calc(expression[begin + 1:end])) # if no function, just a brackets
-
- if sign == '^': # processing power operator section
- power_stack.push(element)
- sign = ''
- else:
- if main_number != '':
- if sign != '':
- if sign in ['*', '/', '//', '%']:
- if number != '':
- main_number = operators_type1[previous_sign](float(main_number), float(number))
- number = element
- previous_sign = sign
- sign = ''
- else:
- main_number = element
- no_numbers_flag = True
- brackets = False
-
- else: # if no in stack
- if element in math_consts: # if element is const
- element = str(math_consts[element])
- elif element == '-e':
- element = str(-1 * math.e)
- elif element == '-pi':
- element = str(-1 * math.pi)
- elif element == '+e':
- element = str(math.e)
- elif element == '+pi':
- element = str(math.pi)
-
- if element == '(': # start extracting expression in brackets
- brackets = True
- begin = index
- stack.push('(')
-
- elif element.isalpha():
- if element in functions: # if element is function
- func = element
- else:
- print("ERROR: function " + func + " does not exists")
- exit()
-
- elif element in signs: # if element is sign
- if element == '^': # processing power operator
- sign = '^'
- if not no_numbers_flag:
- print("ERROR: no numbers before " + sign)
- else:
- if not power_stack.is_empty():
- last = float(power_stack.pop())
- if power_stack.is_empty():
- if number != '':
- number = str(float(number) ** last)
- else:
- main_number = str(float(main_number) ** last)
- else:
- while not power_stack.is_empty():
- last = float(power_stack.pop()) ** last
- main_number = str(float(main_number) ** last)
- no_numbers_flag = True
-
- if element in ['+', '-']: # processing + or -
- if main_number != '':
- if number != '':
- main_number = operators_type1[previous_sign](float(main_number), float(number))
- number = ''
- previous_sign = ''
- no_numbers_flag = True
- result = operators_main[main_sign](result, float(main_number))
- main_number = ''
- main_sign = element
-
- elif element in ['*', '/', '//', '%']: # processing other operators
- sign = element
- if not no_numbers_flag:
- print("ERROR: no numbers before " + sign)
- else: # element is number
- if sign == '^': # if power operator stays before this element
- power_stack.push(element)
- sign = ''
- else:
- if main_number != '': # if main_number was found
- if sign != '':
- if sign in ['*', '/', '//', '%']:
- if number != '':
- main_number = operators_type1[previous_sign](float(main_number), float(number))
- number = element
- previous_sign = sign
- sign = ''
- else:
- main_number = element
- no_numbers_flag = True
-
- if not no_numbers_flag:
- print("ERROR: No numbers in exrpession")
- exit()
- if main_number != '': # adding last number to result
- if main_sign == '+':
- result += float(main_number)
- elif main_sign == '-':
- result -= float(main_number)
- if result == 0 and main_number == '':
- return ''
- else:
- return str(result)
-
-
-def pycalc(expression, modules=list()):
- global functions
- if 'math' not in modules: # including module math
- modules.append('math')
- for module in modules: # adding all functions to dictionary
- workspace = importlib.import_module(module)
- for name in dir(workspace):
- functions[name] = getattr(workspace, name)
-
- expression = separate(expression) # separating expression (look separate function)
- if check_mistakes(expression): # handling some mistakes
- for index, element in enumerate(expression): # looking for logical signs
- if element in logical_signs:
- left = float(calc(expression[:index]))
- right = float(calc(expression[index + 1:]))
- return logical_signs[element](left, right)
- result = float(calc(expression)) # start counting
- return result
From 73b5be7598909d4ed420a8ba8831b7d24981640d Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 01:38:14 +0300
Subject: [PATCH 32/73] Delete main.cpython-36.pyc
---
pycalc/__pycache__/main.cpython-36.pyc | Bin 5755 -> 0 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 pycalc/__pycache__/main.cpython-36.pyc
diff --git a/pycalc/__pycache__/main.cpython-36.pyc b/pycalc/__pycache__/main.cpython-36.pyc
deleted file mode 100644
index 8dd584c2c08c23570e1a3c8e7ea2492a18a81201..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 5755
zcmZu#O^h5z74EA3o!Ob$*&pwZezOR^&zqXNaPZsC_-p2@V%;@nYHnZ
zs=E5stJhWU)qCHodahh9Uisrc-cFu3jK3KNej{jKLW%y2N*IE*jdkX8)iQlkJuTl-
zPusWE)A1d_g()my3rD!Z69rKeBcilA;=6&h?x7S=iYOx}B`TtP&+*G>RZvDzswiWk
za?kR|(V9S+6r=aJe<-lmr%l@aY;ahN-Q$fTVq8qzG5n)qQXInbn3xjNcpeus
zViwO6L2buaVdAhja)SKD*H4
zb09rdcccf-9={061(e57&R>uP5bKt-@Q}7*n46O>5xL|GbSXWoLOiD$+>JM$T}_Sw_>tp3@5@v9dyvmJz))97{sEYn_$
z8_TV%5QJMBfo#M<<~5_GV51w~&g_+Trx9n?a-+SRS>3H@Ei=2FZr#a>!FE>$QPk`}
z5*k}=uz~VkW=Be%-3r4O&CSzcA#JG>HpyYn_c?E^M|s?Z({I+skVWxp7r?)`R6Z
zntLS_GHA}NG{Z)FDQ-lqx$bTH@Z3hD8J_Fj&b-wiUTVnI=xGRxj-xVIiCL_OVlj`6
zvno5z9JETR$fv+Dupn8Pin8E$(KukinV1PqIu+)kk=u=Jzn&Pd+4+={RiNjKuoFB+
z>HZ{WWRH`ekqv!FaQYHJvz0wgl0B$D>K*JC?$AcP={K%j`_{FWYf9s_p;|A?2~1K>
zqUs&bd2UIVDu|<6Lk6|56W6+prVPY&Z2c+lWp-CK!&uJHz++S$riwIGH{}UD{7PTM
zk~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.noreply.github.com>
Date: Thu, 23 May 2019 01:38:21 +0300
Subject: [PATCH 33/73] Delete stack.cpython-36.pyc
---
pycalc/__pycache__/stack.cpython-36.pyc | Bin 901 -> 0 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 pycalc/__pycache__/stack.cpython-36.pyc
diff --git a/pycalc/__pycache__/stack.cpython-36.pyc b/pycalc/__pycache__/stack.cpython-36.pyc
deleted file mode 100644
index 0495dfc89969b56d17ef2e4f1892f8700db3cf7c..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 901
zcmaJW}pAO<#s#8x3$R?ekq^JDCEDC$;ThF8jpcnK!%
zoVF?maCASp^WAqpKI`}6Q}OY5!WnyKJ10Q>3dtQKyJf(Dzap)~h=F)ugCIrw_6XFj
zklZ;k%|;y9NB{@%%0>YM5TXpB16`CI=s|?C3wscw?7=?fJ7_u&wMu6x7UB;{N_&Ik
zVq{Nj$s`tnm-*d*H+|^?q|9nvI5dP#=i@hKL%jTXnM|reCuKIPa+TaK(uuOgy{)D?
ztzB|mg4J0v&PtWbTDe(b7OBe9#8C}HvuGmBTV}PCRD&bN_{*V39By2H*Scg=tanC(
zqFOD*qoASs@>7(%$`vS
Date: Thu, 23 May 2019 01:38:32 +0300
Subject: [PATCH 34/73] Delete stack.cpython-37.pyc
---
pycalc/__pycache__/stack.cpython-37.pyc | Bin 753 -> 0 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 pycalc/__pycache__/stack.cpython-37.pyc
diff --git a/pycalc/__pycache__/stack.cpython-37.pyc b/pycalc/__pycache__/stack.cpython-37.pyc
deleted file mode 100644
index eeb3e0061512f03951fa221441f9218ad88570f7..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 753
zcmZuty>8nu5Wb^iNm1<}&DhCfJv39NqA1cfXf`eGBnTiBk*OWaGAqi1f=o@Gqe#ZS
zPbaRK`U;(TM>#KB~IvrEm*Hkp*s2~^LAP*EOaRYg%0u@ppsga7PM=B8rA?3J-Z?dKa3lU4$&n
zuMGu`F~kTjQ%`=x&lT;_2lq!SujtaJgOxjyy)!{}ya|z!hnCH|z--J6TW0Z6hZ6I3
zkID;5n@|B_Pnmmf$GtJns2R*}k*PZ%YP?2;E72bM-32@9F#E%3eu+V?8?WO30$j4R
zQm;+dzoZGv<^cCG6qoyhhKJ{D7P~~srd(?&T`J{zqqa4l$5MXZmi6%BsaiJUt+iu5
oG3t}zjq@rwz43$ylQ@Z5{*#eX?oTE>0FSxk{lNRd&(a_G2Prv@)&Kwi
From 27d0a1f2891e84c2e616eeadc2d3e5f2b57ee30a Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 01:38:55 +0300
Subject: [PATCH 35/73] Delete setup.py
---
setup.py | 14 --------------
1 file changed, 14 deletions(-)
delete mode 100644 setup.py
diff --git a/setup.py b/setup.py
deleted file mode 100644
index 796ebaba..00000000
--- a/setup.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from setuptools import setup
-
-setup(name='pycalc',
- version='0.1',
- author_email='andrey-truhan@tut.by',
- description='Alpha version pure-python command-line calculator',
- author='Andrei Trukhan',
- license='free',
- packages=['pycalc'],
- zip_safe=False,
- entry_points={
- "console_scripts": ["pycalc=pycalc.start:main"]
- },
- )
From a6b659f1ce627af6b9dc9443c4999c9236444c52 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 01:39:23 +0300
Subject: [PATCH 36/73] Add files via upload
---
final_task/pycalc/main.py | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 983e1c99..155565c0 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -59,6 +59,7 @@ def check_mistakes(expression):
if len(expression) == 0:
print("ERROR: empty expression")
return False
+
brackets_stack = Stack.Stack()
for element in expression:
if element == '(':
@@ -71,6 +72,14 @@ def check_mistakes(expression):
if not brackets_stack.is_empty():
print("ERROR: brackets are not paired")
return False
+
+ for element in expression:
+ number = ''
+ if element in ['*', '/', '^', '%', '>', '<', '=', '//', '!'] and number == '':
+ print("ERROR: no numbers before " + element)
+ elif element not in signs and element != ' ':
+ break
+
return True
@@ -201,7 +210,6 @@ def calc(expression):
previous_sign = '' # additionaly variable for sign
stack = Stack.Stack() # stack for brackets
power_stack = Stack.Stack() # stack for powered numbers
- no_numbers_flag = False
for index, element in enumerate(expression):
if brackets: # if in we find expression in brackets, we start searching of end bracket with stack
@@ -235,7 +243,6 @@ def calc(expression):
sign = ''
else:
main_number = element
- no_numbers_flag = True
brackets = False
else: # if no in stack
@@ -265,8 +272,6 @@ def calc(expression):
elif element in signs: # if element is sign
if element == '^': # processing power operator
sign = '^'
- if not no_numbers_flag:
- print("ERROR: no numbers before " + sign)
else:
if not power_stack.is_empty():
last = float(power_stack.pop())
@@ -279,7 +284,6 @@ def calc(expression):
while not power_stack.is_empty():
last = float(power_stack.pop()) ** last
main_number = str(float(main_number) ** last)
- no_numbers_flag = True
if element in ['+', '-']: # processing + or -
if main_number != '':
@@ -287,15 +291,12 @@ def calc(expression):
main_number = operators_type1[previous_sign](float(main_number), float(number))
number = ''
previous_sign = ''
- no_numbers_flag = True
result = operators_main[main_sign](result, float(main_number))
main_number = ''
main_sign = element
elif element in ['*', '/', '//', '%']: # processing other operators
sign = element
- if not no_numbers_flag:
- print("ERROR: no numbers before " + sign)
else: # element is number
if sign == '^': # if power operator stays before this element
power_stack.push(element)
@@ -311,11 +312,8 @@ def calc(expression):
sign = ''
else:
main_number = element
- no_numbers_flag = True
- if not no_numbers_flag:
- print("ERROR: No numbers in exrpession")
- exit()
+
if main_number != '': # adding last number to result
if main_sign == '+':
result += float(main_number)
From 63a3c3b92ee8460575a63d46a5a1e07752e76b27 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 01:40:50 +0300
Subject: [PATCH 37/73] Add files via upload
---
final_task/pycalc/main.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 155565c0..41bde605 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -76,7 +76,7 @@ def check_mistakes(expression):
for element in expression:
number = ''
if element in ['*', '/', '^', '%', '>', '<', '=', '//', '!'] and number == '':
- print("ERROR: no numbers before " + element)
+ print("ERROR: no numbers before sign")
elif element not in signs and element != ' ':
break
From 0e7fc078177fa2408e78713fbf7a3d8fa5238fb5 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 01:55:29 +0300
Subject: [PATCH 38/73] Add files via upload
---
final_task/pycalc/main.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 41bde605..95343cef 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -313,7 +313,6 @@ def calc(expression):
else:
main_number = element
-
if main_number != '': # adding last number to result
if main_sign == '+':
result += float(main_number)
From ea8c2c6798556a6b3818c19ad7b141551f000c8e Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 02:09:29 +0300
Subject: [PATCH 39/73] Calculation worked. Input defense requred
---
final_task/dist/pycalc-0.1.tar.gz | Bin 0 -> 3724 bytes
final_task/pycalc.egg-info/PKG-INFO | 10 +++++
final_task/pycalc.egg-info/SOURCES.txt | 10 +++++
.../pycalc.egg-info/dependency_links.txt | 1 +
final_task/pycalc.egg-info/entry_points.txt | 3 ++
final_task/pycalc.egg-info/not-zip-safe | 1 +
final_task/pycalc.egg-info/top_level.txt | 1 +
.../pycalc/__pycache__/main.cpython-36.pyc | Bin 5755 -> 4043 bytes
.../pycalc/__pycache__/stack.cpython-36.pyc | Bin 901 -> 759 bytes
final_task/pycalc/main.py | 35 ++++++------------
final_task/setup.py | 7 +++-
final_task/setup.sh | 4 ++
12 files changed, 46 insertions(+), 26 deletions(-)
create mode 100644 final_task/dist/pycalc-0.1.tar.gz
create mode 100644 final_task/pycalc.egg-info/PKG-INFO
create mode 100644 final_task/pycalc.egg-info/SOURCES.txt
create mode 100644 final_task/pycalc.egg-info/dependency_links.txt
create mode 100644 final_task/pycalc.egg-info/entry_points.txt
create mode 100644 final_task/pycalc.egg-info/not-zip-safe
create mode 100644 final_task/pycalc.egg-info/top_level.txt
create mode 100644 final_task/setup.sh
diff --git a/final_task/dist/pycalc-0.1.tar.gz b/final_task/dist/pycalc-0.1.tar.gz
new file mode 100644
index 0000000000000000000000000000000000000000..fa062afea25f0358e9b84f505b403da068c8158a
GIT binary patch
literal 3724
zcmV;74s-DziwFou*5zCR|72-%bT4puV_|G#Eif)IE_7jX0PP%WZ`(%FpZO~o1p&qA
zVac{^oDdaPwCP>Z=7HwgJHS;1T3SgwQzVb1?5IWm`_1fw++DsT*H$i9E)Xf&$L#F9
zXO?uhn>*gTH|P&fPoAm`pj};!@OyYQ8pz+Goea+}u7>BM^Wos?WB@5;D
ziA?jvcW(pFDW6w2E)F8TKa&<_{Ad3?{a@h!#pUH$!~ajif1t$M?DQoONw$%%tyGtW+jvcvbxj;E*{|<}A@LV&Iz?I>gnMk+
z$7#~4*!`81Ec1xpmY3Sb$^Uc9>;J}a{YO>*8vQ>XT#hbu{U2UkHTr*y=5E3uN=(N4
zKDGU(!wrJL2iceB-iVGMB$1N@k@&rFlC}7ML<}Q#S3WfmR>$g^Ru4a3;>Rg|{DL1Z
z@Z$^oc!eJmI!cG1SzsHyVC4cvGXd#0s;01DoNnGy((Uuv
ztyhzl)a|9+YOnFTVHo0fJWF;V8D{9clp$}n9^dg)?oOgDS-5v%NEustK@eqwFBEXW
z0yoe0Mm^28?#OeU#e#$A$=&hx20*h(1nBINI!J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Y
z^#RvUlnYP3=L>VFz3`E}P=Nn9gsMj$*knG@NaHLWftw)k^j8+dqLZdQ)c(K!?r*(s
z-+uG%N#6gjdjI=;G}7Py9}SxKKabMhK)AYa5~ueQiRd%^=CD67-a^DW=1#y!M?gr7
z4_h$Y(Qa&h>4j^@yklc#SZ~{nze8-<3!N1}{_*X1Z{Pj%t?}g+Rzv{IUqr;k(*G@l
zqP)9Dz}I+VOpGG3>m|_^#{QaYlm5-l_}-lp9}6wZh!ErJ%+F-N-@~>Ld~ULyM%}CQ
zKZam4eB3v`_tXE&T>Lj0o?SNje~h+_f{jTzp9J_^HIM&jk73ZSHs-Gri%Civ?QqSX
zSRguSr$ZHYMimzVp8~~Ar^=zBb+9qfb_58D1xbfJW+o;Unu)X*((+rdLoozb{8Uph
z^s5`rVrNMv^rBnzLZ}$+W?=x4Mm+f~4Lw?T(HwYW#*PxV#^$vW(6ku%N%neul#DTg
zZe>B^)c9TefFSOZ|NVzPS*?1mzYIMzsNd2
ziT=Y+RsYYq3_
zy43ama@6SmQQEau!kqF98ZVjkqNUN8i9eJ6%XO6}&HwZ9|KM`a#Q#nF-?U@uKPv^#
zm#fF#qgMZ~&b9lW(b@T+(f_0Pe=zqmH1|^@aaObV&Y$7C0Q?E%0qtDiBgW##&DQns
quQ)WpK+~Gmw5Bz!X-#Wd)0)<_rZuf;O>5d`(f$hv5Oc`@cmM!(Msw2u
literal 0
HcmV?d00001
diff --git a/final_task/pycalc.egg-info/PKG-INFO b/final_task/pycalc.egg-info/PKG-INFO
new file mode 100644
index 00000000..f7d7d56b
--- /dev/null
+++ b/final_task/pycalc.egg-info/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: pycalc
+Version: 0.1
+Summary: Alpha version pure-python command-line calculator
+Home-page: UNKNOWN
+Author: Andrei Trukhan
+Author-email: andrey-truhan@tut.by
+License: free
+Description: UNKNOWN
+Platform: UNKNOWN
diff --git a/final_task/pycalc.egg-info/SOURCES.txt b/final_task/pycalc.egg-info/SOURCES.txt
new file mode 100644
index 00000000..26c30242
--- /dev/null
+++ b/final_task/pycalc.egg-info/SOURCES.txt
@@ -0,0 +1,10 @@
+setup.py
+pycalc/main.py
+pycalc/stack.py
+pycalc/start.py
+pycalc.egg-info/PKG-INFO
+pycalc.egg-info/SOURCES.txt
+pycalc.egg-info/dependency_links.txt
+pycalc.egg-info/entry_points.txt
+pycalc.egg-info/not-zip-safe
+pycalc.egg-info/top_level.txt
\ No newline at end of file
diff --git a/final_task/pycalc.egg-info/dependency_links.txt b/final_task/pycalc.egg-info/dependency_links.txt
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/final_task/pycalc.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/final_task/pycalc.egg-info/entry_points.txt b/final_task/pycalc.egg-info/entry_points.txt
new file mode 100644
index 00000000..58b68d8b
--- /dev/null
+++ b/final_task/pycalc.egg-info/entry_points.txt
@@ -0,0 +1,3 @@
+[console_scripts]
+pycalc = pycalc.start:main
+
diff --git a/final_task/pycalc.egg-info/not-zip-safe b/final_task/pycalc.egg-info/not-zip-safe
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/final_task/pycalc.egg-info/not-zip-safe
@@ -0,0 +1 @@
+
diff --git a/final_task/pycalc.egg-info/top_level.txt b/final_task/pycalc.egg-info/top_level.txt
new file mode 100644
index 00000000..f6ff781f
--- /dev/null
+++ b/final_task/pycalc.egg-info/top_level.txt
@@ -0,0 +1 @@
+pycalc
diff --git a/final_task/pycalc/__pycache__/main.cpython-36.pyc b/final_task/pycalc/__pycache__/main.cpython-36.pyc
index 8dd584c2c08c23570e1a3c8e7ea2492a18a81201..83496fd7a1f91edc4acb362330771bc955d8739d 100644
GIT binary patch
literal 4043
zcmZ`+J!~Au6`q;>xxKv~{+&pQ4irlMiBDogLKb92kO&(wlE5$oK@zNBVVhXpEXm^?
z_wHtg_DR@HLnnm`gLNRdaF@UcQlwUqE-6x_+9p5}1W}VJ)iufYX75KN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sBPOU*3KJdRp~V~%T%c9+LJ|mf
zsjrlet1?fuz|E>?DIPY?$9W0kAWil5?fXCdAh>C}GAH
zSF2v8%Om|bpLY>w?asK$~ILQ3!&KtVj^@3!AU%t8xet^keg)WP|u&~l`Ri$EZFZ({fF
zj#5|C5C=G-zA>N^f)c{IiMNBKb5r0uYBb$9rG=!BM*(v|UcqW~8duV(TcNqp?Z~*@
zyycg5b7`X^w%S2vil)q5T+uY*SjsnPAZ0G?{{QN=cQKI!0ps(mLgJ>4TVYdZ
z({&MTzZpDBOnwIwtUvCT^r&;{azy!yzD&7F^Y{8GsaDH8t?m+a@YNV4$at`s@et2;
zAQ!2_+}LVoZY;L~(R?rSaGTbV)H1O^6&P^IC~(slZQWA-u0nzi4iqtDg{o1ils+lQ
zXniWpQh3QMb#SBUAJD*14c>XJ%ZqdtiEwjlkngEKKYYMTi?;UFqJ{f3Rf?uJ?oD{1
I_dTQfKj4ZDlK=n!
diff --git a/final_task/pycalc/__pycache__/stack.cpython-36.pyc b/final_task/pycalc/__pycache__/stack.cpython-36.pyc
index 0495dfc89969b56d17ef2e4f1892f8700db3cf7c..e728331c34e4e805dbeba30de868055932f2ea99 100644
GIT binary patch
literal 759
zcmZutJ8#=C5I$0}q^Ne#CR?YD^%4zTiy%dTbQ1zNlMsL)M7nfW
z$t(9F*s0%`ENq=>kKO0coqK_
z;F7f!y6*bn9ZpzUDX>!(^83?K!%I7#$1V|~k+l}Wr9#xL+EsL)3h`qntFhy$44LuP
q%#?0~dX&6zS|x=yo*-coCy}9-9Fu`7x)WaS&?u6
literal 901
zcmaJW}pAO<#s#8x3$R?ekq^JDCEDC$;ThF8jpcnK!%
zoVF?maCASp^WAqpKI`}6Q}OY5!WnyKJ10Q>3dtQKyJf(Dzap)~h=F)ugCIrw_6XFj
zklZ;k%|;y9NB{@%%0>YM5TXpB16`CI=s|?C3wscw?7=?fJ7_u&wMu6x7UB;{N_&Ik
zVq{Nj$s`tnm-*d*H+|^?q|9nvI5dP#=i@hKL%jTXnM|reCuKIPa+TaK(uuOgy{)D?
ztzB|mg4J0v&PtWbTDe(b7OBe9#8C}HvuGmBTV}PCRD&bN_{*V39By2H*Scg=tanC(
zqFOD*qoASs@>7(%$`vS', '<', '=', '//', '!'] and number == '':
- print("ERROR: no numbers before sign")
- elif element not in signs and element != ' ':
- break
-
return True
@@ -95,7 +86,7 @@ def separate(expression): # separates expression to logical parts
def check_log10():
nonlocal current
nonlocal expression_list
- if current == '10' and expression_list[len(expression_list) - 1] == 'log':
+ if current == '10' and expression_list[len(expression_list)-1] == 'log':
expression_list.pop()
expression_list.append('log10')
current = ''
@@ -182,11 +173,11 @@ def is_number(string):
expression_list.append(current)
index = 1
- while index <= len(expression_list) - 1:
+ while index <= len(expression_list)-1:
if expression_list[index] in operators_main and\
- (expression_list[index - 1] in operators_type1 or expression_list[index - 1] == '^') and\
- (is_number(expression_list[index + 1]) or expression_list[index + 1] in math_consts):
- expression_list[index + 1] = expression_list[index] + expression_list[index + 1]
+ (expression_list[index-1] in operators_type1 or expression_list[index-1] == '^') and\
+ (is_number(expression_list[index+1]) or expression_list[index+1] in math_consts):
+ expression_list[index+1] = expression_list[index] + expression_list[index + 1]
expression_list.pop(index)
else:
index += 1
@@ -262,12 +253,8 @@ def calc(expression):
begin = index
stack.push('(')
- elif element.isalpha():
- if element in functions: # if element is function
- func = element
- else:
- print("ERROR: function " + func + " does not exists")
- exit()
+ elif element in functions: # if element is function
+ func = element
elif element in signs: # if element is sign
if element == '^': # processing power operator
@@ -338,7 +325,7 @@ def pycalc(expression, modules=list()):
for index, element in enumerate(expression): # looking for logical signs
if element in logical_signs:
left = float(calc(expression[:index]))
- right = float(calc(expression[index + 1:]))
+ right = float(calc(expression[index+1:]))
return logical_signs[element](left, right)
result = float(calc(expression)) # start counting
return result
diff --git a/final_task/setup.py b/final_task/setup.py
index 796ebaba..22fefbae 100644
--- a/final_task/setup.py
+++ b/final_task/setup.py
@@ -9,6 +9,9 @@
packages=['pycalc'],
zip_safe=False,
entry_points={
- "console_scripts": ["pycalc=pycalc.start:main"]
- },
+ "console_scripts": [
+ "pycalc=pycalc.start:main",
+ ]
+},
)
+
diff --git a/final_task/setup.sh b/final_task/setup.sh
new file mode 100644
index 00000000..f29b6ec4
--- /dev/null
+++ b/final_task/setup.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+python setup.py sdist;
+sudo pip install dist/pycalc-0.1.tar.gz;
+
From 42d53e23055994b437772f3449fa6d4f1fcef6e7 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 02:27:13 +0300
Subject: [PATCH 40/73] Add files via upload
---
final_task/pycalc/main.py | 45 ++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 12 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 1112b8a9..cabbd4f8 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -57,31 +57,47 @@ def get_args(expression):
def check_mistakes(expression):
if len(expression) == 0:
- print("Error: empty expression!")
+ print("ERROR: empty expression!")
return False
+
brackets_stack = Stack.Stack()
for element in expression:
if element == '(':
brackets_stack.push('(')
elif element == ')':
if brackets_stack.is_empty():
- print("Error: brackets are not paired")
+ print("ERROR: brackets are not paired")
return False
brackets_stack.pop()
if not brackets_stack.is_empty():
- print("Error: brackets are not paired")
+ print("ERROR: brackets are not paired")
return False
- return True
+ main_sign_count = 0
+ l_sign_count = 0
+ number_count = 0
-def separate(expression): # separates expression to logical parts
- new = ''
+ for index in range(len(expression)):
+ if expression[index] in ['+', '-']:
+ main_sign_count += 1
+ if number_count == 0:
+ print("ERROR: no numbers before sign")
+ return False
- for char in expression:
- if char != ' ':
- new += char
+ if expression[index] in ['*', '/', '^', '%', '//']:
+ if expression[index + 1] in ['*', '/', '^', '%', '//']:
+ print("ERROR: wrong signs position")
+ return False
+
+ if expression[index] in logical_signs:
+ l_sign_count +=1
+ if l_sign_count > 1:
+ print("ERROR: more than one logical operator")
+ return False
+ return True
- expression = new
+
+def separate(expression): # separates expression to logical parts
def check_log10():
nonlocal current
@@ -320,8 +336,13 @@ def pycalc(expression, modules=list()):
for name in dir(workspace):
functions[name] = getattr(workspace, name)
- expression = separate(expression) # separating expression (look separate function)
- if check_mistakes(expression): # handling some mistakes
+ new = ''
+
+ for char in expression:
+ if char != ' ':
+ new += char
+ if check_mistakes(separate(expression)): # handling some mistakes
+ expression = separate(new) # separating expression (look separate function)
for index, element in enumerate(expression): # looking for logical signs
if element in logical_signs:
left = float(calc(expression[:index]))
From 76b31edfcae83190703dcacf932572b481fc1dda Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 02:31:27 +0300
Subject: [PATCH 41/73] Add files via upload
---
final_task/pycalc/main.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index cabbd4f8..bc73a6db 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -69,6 +69,7 @@ def check_mistakes(expression):
print("ERROR: brackets are not paired")
return False
brackets_stack.pop()
+ elif element == " ": expression.remove(element)
if not brackets_stack.is_empty():
print("ERROR: brackets are not paired")
return False
@@ -80,11 +81,11 @@ def check_mistakes(expression):
for index in range(len(expression)):
if expression[index] in ['+', '-']:
main_sign_count += 1
+
+ if expression[index] in ['*', '/', '^', '%', '//']:
if number_count == 0:
print("ERROR: no numbers before sign")
return False
-
- if expression[index] in ['*', '/', '^', '%', '//']:
if expression[index + 1] in ['*', '/', '^', '%', '//']:
print("ERROR: wrong signs position")
return False
From 527ee2165a9adba441febd1ef2b67b46e51e2b91 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 02:37:03 +0300
Subject: [PATCH 42/73] Add files via upload
---
final_task/pycalc/main.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index bc73a6db..13ce95d1 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -82,7 +82,7 @@ def check_mistakes(expression):
if expression[index] in ['+', '-']:
main_sign_count += 1
- if expression[index] in ['*', '/', '^', '%', '//']:
+ elif expression[index] in ['*', '/', '^', '%', '//']:
if number_count == 0:
print("ERROR: no numbers before sign")
return False
@@ -90,11 +90,14 @@ def check_mistakes(expression):
print("ERROR: wrong signs position")
return False
- if expression[index] in logical_signs:
+ elif expression[index] in logical_signs:
l_sign_count +=1
if l_sign_count > 1:
print("ERROR: more than one logical operator")
return False
+
+ elif expression[index].isnumeric():
+ number_count += 1
return True
From 8b2a42d8304ac99383c22a24f976085134dc4bb2 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 02:43:25 +0300
Subject: [PATCH 43/73] Input defense in progress
---
final_task/pycalc/main.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 13ce95d1..9cc96ecd 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -74,6 +74,10 @@ def check_mistakes(expression):
print("ERROR: brackets are not paired")
return False
+ if expression[len(expression)-1] in signs:
+ print("ERROR: no number after operator")
+ return False
+
main_sign_count = 0
l_sign_count = 0
number_count = 0
@@ -98,6 +102,18 @@ def check_mistakes(expression):
elif expression[index].isnumeric():
number_count += 1
+
+ elif expression[index].isalpha():
+ if expression[index] in math_consts:
+ number_count += 1
+ elif expression[index] in functions:
+ if expression[index + 1] != '(':
+ print("ERROR: no brackets after function")
+ return False
+ else:
+ print("ERROR: function does not exist")
+ return False
+
return True
From dc8275736573474ea97b72d7cdb3120deb3ec8c6 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 02:47:40 +0300
Subject: [PATCH 44/73] Add files via upload
---
final_task/pycalc/main.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 9cc96ecd..92da6548 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -56,6 +56,12 @@ def get_args(expression):
def check_mistakes(expression):
+
+ def is_number(expression):
+ for element in expression:
+ if '0' >= element >= '9' and element != '.':
+ return False
+ return True
if len(expression) == 0:
print("ERROR: empty expression!")
return False
@@ -100,7 +106,7 @@ def check_mistakes(expression):
print("ERROR: more than one logical operator")
return False
- elif expression[index].isnumeric():
+ elif is_number(expression[index]):
number_count += 1
elif expression[index].isalpha():
From eaa17b7e0731edc1f7d14560cd296658fc13eada Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 09:18:15 +0300
Subject: [PATCH 45/73] Add files via upload
---
final_task/pycalc/main.py | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 92da6548..a8a13f32 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -80,7 +80,7 @@ def is_number(expression):
print("ERROR: brackets are not paired")
return False
- if expression[len(expression)-1] in signs:
+ if expression[len(expression)] in signs:
print("ERROR: no number after operator")
return False
@@ -88,38 +88,45 @@ def is_number(expression):
l_sign_count = 0
number_count = 0
- for index in range(len(expression)):
+ for index in range(len(expression) - 1):
+
if expression[index] in ['+', '-']:
main_sign_count += 1
elif expression[index] in ['*', '/', '^', '%', '//']:
if number_count == 0:
print("ERROR: no numbers before sign")
- return False
- if expression[index + 1] in ['*', '/', '^', '%', '//']:
print("ERROR: wrong signs position")
return False
elif expression[index] in logical_signs:
l_sign_count +=1
if l_sign_count > 1:
- print("ERROR: more than one logical operator")
- return False
+ print("ERROR: more than one lo"
+ "gical operator")
+ return \
+ False
elif is_number(expression[index]):
number_count += 1
+ if index != len(expression) - 1 and is_number(expression[index + 1]):
+ print("ERROR: no sign between expression")
elif expression[index].isalpha():
if expression[index] in math_consts:
number_count += 1
elif expression[index] in functions:
- if expression[index + 1] != '(':
+ if expression[index + 1] != '(' or index == len(expression) - 1:
print("ERROR: no brackets after function")
return False
else:
print("ERROR: function does not exist")
return False
+ if number_count == 0:
+ print("ERROR: no numbers in expression")
+ return False
+
return True
From 9ca56bf0cd238d62ef79f7969169e027dc3472ab Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 09:19:24 +0300
Subject: [PATCH 46/73] Add files via upload
---
final_task/pycalc/main.py | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index a8a13f32..a1b2e3f2 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -102,10 +102,8 @@ def is_number(expression):
elif expression[index] in logical_signs:
l_sign_count +=1
if l_sign_count > 1:
- print("ERROR: more than one lo"
- "gical operator")
- return \
- False
+ print("ERROR: more than one logical operator")
+ return False
elif is_number(expression[index]):
number_count += 1
From d7652fd1b2beecb107d94a541854268139015972 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 09:23:30 +0300
Subject: [PATCH 47/73] Input defense in process
---
final_task/pycalc/main.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index a1b2e3f2..8aecb860 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -62,6 +62,7 @@ def is_number(expression):
if '0' >= element >= '9' and element != '.':
return False
return True
+
if len(expression) == 0:
print("ERROR: empty expression!")
return False
@@ -80,7 +81,7 @@ def is_number(expression):
print("ERROR: brackets are not paired")
return False
- if expression[len(expression)] in signs:
+ if expression[len(expression)-1] in signs:
print("ERROR: no number after operator")
return False
From 8c2c0091edcab0db61f3a630d8e208b0c45cfb8d Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 09:37:52 +0300
Subject: [PATCH 48/73] Add files via upload
---
final_task/pycalc/main.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 8aecb860..b0398b0c 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -59,7 +59,7 @@ def check_mistakes(expression):
def is_number(expression):
for element in expression:
- if '0' >= element >= '9' and element != '.':
+ if not element.isnumeric() and element != '.':
return False
return True
@@ -89,7 +89,7 @@ def is_number(expression):
l_sign_count = 0
number_count = 0
- for index in range(len(expression) - 1):
+ for index in range(len(expression)):
if expression[index] in ['+', '-']:
main_sign_count += 1
@@ -101,10 +101,13 @@ def is_number(expression):
return False
elif expression[index] in logical_signs:
- l_sign_count +=1
+ l_sign_count += 1
if l_sign_count > 1:
print("ERROR: more than one logical operator")
return False
+ elif expression[index] == '=':
+ print("ERROR: illegal usage '='")
+ return False
elif is_number(expression[index]):
number_count += 1
From 8ff0bbe3ae81716b4646f7bfc97e52ed99693ed4 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 09:52:13 +0300
Subject: [PATCH 49/73] Almost release
---
final_task/pycalc/main.py | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index b0398b0c..6e5fd88c 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -88,6 +88,7 @@ def is_number(expression):
main_sign_count = 0
l_sign_count = 0
number_count = 0
+ logical_sign_pos = 0
for index in range(len(expression)):
@@ -97,7 +98,9 @@ def is_number(expression):
elif expression[index] in ['*', '/', '^', '%', '//']:
if number_count == 0:
print("ERROR: no numbers before sign")
- print("ERROR: wrong signs position")
+ return False
+ if index != len(expression) - 1 and expression[index + 1] in ['*', '/', '^', '%', '//']:
+ print("ERROR: duplicate multiply or div sign")
return False
elif expression[index] in logical_signs:
@@ -118,13 +121,17 @@ def is_number(expression):
if expression[index] in math_consts:
number_count += 1
elif expression[index] in functions:
- if expression[index + 1] != '(' or index == len(expression) - 1:
+ if index == len(expression) - 1 or expression[index + 1] != '(':
print("ERROR: no brackets after function")
return False
else:
print("ERROR: function does not exist")
return False
+ if l_sign_count == 1:
+ if (len(expression[:logical_sign_pos])) == 0 or (len(expression[logical_sign_pos:])) == 0:
+ print("ERROR: one of expressions around logical operator is empty")
+ return False
if number_count == 0:
print("ERROR: no numbers in expression")
return False
@@ -263,11 +270,16 @@ def calc(expression):
end = index
if func != '': # if we find function
temp = get_args(expression[begin + 1:end]) # getting arguments for func
- if temp != ['']:
- element = functions[func](*temp) # processing function with 1 or more args
- else:
- element = functions[func]() # processing function with no args
- func = ''
+ try:
+ if temp != ['']:
+ element = functions[func](*temp) # processing function with 1 or more args
+ else:
+ element = functions[func]() # processing function with no args
+
+ func = ''
+ except TypeError:
+ print("ERROR: wrong amount of arguments for " + func + "(..)")
+ exit()
else:
element = float(calc(expression[begin + 1:end])) # if no function, just a brackets
From b5735e416249940d9f61cbaada3c36bd3666f585 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 09:58:18 +0300
Subject: [PATCH 50/73] Almost release. Tests required
---
final_task/pycalc/main.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 6e5fd88c..065e3767 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -57,9 +57,9 @@ def get_args(expression):
def check_mistakes(expression):
- def is_number(expression):
- for element in expression:
- if not element.isnumeric() and element != '.':
+ def is_number(part):
+ for char in part:
+ if not char.isnumeric() and char != '.':
return False
return True
@@ -76,7 +76,8 @@ def is_number(expression):
print("ERROR: brackets are not paired")
return False
brackets_stack.pop()
- elif element == " ": expression.remove(element)
+ elif element == " ":
+ expression.remove(element)
if not brackets_stack.is_empty():
print("ERROR: brackets are not paired")
return False
@@ -105,6 +106,7 @@ def is_number(expression):
elif expression[index] in logical_signs:
l_sign_count += 1
+ logical_sign_pos = index
if l_sign_count > 1:
print("ERROR: more than one logical operator")
return False
From c2c54440fece3599e3a483965b9a0f02e0145e03 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 10:09:51 +0300
Subject: [PATCH 51/73] PEP8
---
final_task/setup.py | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/final_task/setup.py b/final_task/setup.py
index 22fefbae..dacfddfc 100644
--- a/final_task/setup.py
+++ b/final_task/setup.py
@@ -10,8 +10,4 @@
zip_safe=False,
entry_points={
"console_scripts": [
- "pycalc=pycalc.start:main",
- ]
-},
- )
-
+ "pycalc=pycalc.start:main"]})
From 656a84103dca1c33eb7e8335e4b1b13945ffdc92 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 10:12:57 +0300
Subject: [PATCH 52/73] PEP8
---
final_task/pycalc/main.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 065e3767..96244e1e 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -82,7 +82,7 @@ def is_number(part):
print("ERROR: brackets are not paired")
return False
- if expression[len(expression)-1] in signs:
+ if expression[len(expression) - 1] in signs:
print("ERROR: no number after operator")
return False
@@ -146,7 +146,7 @@ def separate(expression): # separates expression to logical parts
def check_log10():
nonlocal current
nonlocal expression_list
- if current == '10' and expression_list[len(expression_list)-1] == 'log':
+ if current == '10' and expression_list[len(expression_list) - 1] == 'log':
expression_list.pop()
expression_list.append('log10')
current = ''
@@ -233,11 +233,11 @@ def is_number(string):
expression_list.append(current)
index = 1
- while index <= len(expression_list)-1:
+ while index <= len(expression_list) - 1:
if expression_list[index] in operators_main and\
- (expression_list[index-1] in operators_type1 or expression_list[index-1] == '^') and\
- (is_number(expression_list[index+1]) or expression_list[index+1] in math_consts):
- expression_list[index+1] = expression_list[index] + expression_list[index + 1]
+ (expression_list[index - 1] in operators_type1 or expression_list[index - 1] == '^') and\
+ (is_number(expression_list[index + 1]) or expression_list[index + 1] in math_consts):
+ expression_list[index + 1] = expression_list[index] + expression_list[index + 1]
expression_list.pop(index)
else:
index += 1
@@ -395,7 +395,7 @@ def pycalc(expression, modules=list()):
for index, element in enumerate(expression): # looking for logical signs
if element in logical_signs:
left = float(calc(expression[:index]))
- right = float(calc(expression[index+1:]))
+ right = float(calc(expression[index + 1:]))
return logical_signs[element](left, right)
result = float(calc(expression)) # start counting
return result
From d723055c42d9d2b90d7a6bfc156d1399583b79cc Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 10:19:01 +0300
Subject: [PATCH 53/73] Add files via upload
---
final_task/setup.py | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/final_task/setup.py b/final_task/setup.py
index dacfddfc..19d54634 100644
--- a/final_task/setup.py
+++ b/final_task/setup.py
@@ -8,6 +8,4 @@
license='free',
packages=['pycalc'],
zip_safe=False,
- entry_points={
- "console_scripts": [
- "pycalc=pycalc.start:main"]})
+ entry_points={"console_scripts": ["pycalc=pycalc.start:main"]})
From 38d6481a87808ef7bebf42327abc90b260c55067 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 11:02:07 +0300
Subject: [PATCH 54/73] Add files via upload
---
.../__pycache__/check_mistakes.cpython-36.pyc | Bin 0 -> 1964 bytes
.../pycalc/__pycache__/consts.cpython-36.pyc | Bin 0 -> 570 bytes
.../pycalc/__pycache__/main.cpython-36.pyc | Bin 4043 -> 4960 bytes
.../pycalc/__pycache__/stack.cpython-36.pyc | Bin 759 -> 912 bytes
final_task/pycalc/check_mistakes.py | 82 +++++++++++
final_task/pycalc/consts.py | 32 +++++
final_task/pycalc/main.py | 128 +-----------------
final_task/pycalc/start.py | 10 +-
final_task/pycalc/test_main.py | 36 +++++
9 files changed, 162 insertions(+), 126 deletions(-)
create mode 100644 final_task/pycalc/__pycache__/check_mistakes.cpython-36.pyc
create mode 100644 final_task/pycalc/__pycache__/consts.cpython-36.pyc
create mode 100644 final_task/pycalc/check_mistakes.py
create mode 100644 final_task/pycalc/consts.py
create mode 100644 final_task/pycalc/test_main.py
diff --git a/final_task/pycalc/__pycache__/check_mistakes.cpython-36.pyc b/final_task/pycalc/__pycache__/check_mistakes.cpython-36.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..ae221052888e642e6b62212ffd9f1aab9803eb58
GIT binary patch
literal 1964
zcmah~O>Y}T7@nE^@Y-?Gl7=)XwA~=m)_lYV4oFcO6(|)4)JArsqNv5%>`d(Ses*SD
z9Ba+R@vuVWWuR0EPGvV6`o)T5Cf?
zV*{26s{+e9#lvr9rLdjg2j~<(+Z|U^lvXzpy$)W#r3S5jj>g9GS0#GGH%~ENPr)B*
z_?xamWz~5$Ujyx#vZd9lkelAj?a%0yHk!qdR*v0I%{;c5R>zi-eO>v|wYepI*C&9r
z=sIK}MFkTK$j^{p)m8bA+__zmJ-0ohSLYG?Rp7JiMb`2|7>PvBs|8pTW)FJ*_
z=*uWNr5h?X-Bdf=f$D;s68=yzLQ!h{L^jL&KPBQzg{Bro7g0d8IfGpS*&zbG20iC2
z!|8y&2ekmr57o6XPH`ViP#tkI#T5G*Hz|P<%_lGd
z5JZ2J;hl#EFvC?(M1zoV&ux%QPaG~Y-R(L2SHvxdIBhk1ambpH=f{E5+&@veaG%G0
z=1S50BBGpm&0{Zef{t{AzbGart`oRTx5r$+6M8~AJ`+31iOSi5q(_XaCnHoIgll*e
zTX?kfhWXtfhA3ih=iG;@_D36Ew_1-|yEY3Gd1A9+!kG|W9BobUohfdNZj|~X4sVr7
zVLP1JQ7rAm@i?PXY`@Oq+$`;)*e*)4ony(k9Vd)CGUikK@f3f`70pxJoZ|1Ncza5k
z&C&HY9ff_wj$_CoylynwF4c691fJ_iW`~17dP#6%$K0mgi;HHVa+EzMvg3%^LEHtO
zV4;Y6=M8&7z`CFt2&c>J+xKpdw&s1QC!dHEs}-pE!LNz2H}^0VtyI6hLO|F-%-G-
z+ODW=?SE8DnHI2!t49HYJP^Iif|<$ZBh!*N$xP0|_yx-h#gfPj?nGUdEth0>3bf)0
zCrEluwiG(D*Ky-WNYSWewfTr;)fq=Z{iUG8l^LfUm~q$7DlA|ji{#;@(D9-?Fa#O^
zP!BGgiiswp2Xw9o1+-
h{c?#E%;km)9jLd?^ERxzVN3@B+f&a_=&(V_+Q0r!67c{4
literal 0
HcmV?d00001
diff --git a/final_task/pycalc/__pycache__/consts.cpython-36.pyc b/final_task/pycalc/__pycache__/consts.cpython-36.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..36e4ff548858d53a18d113067e60fbb5052dcf83
GIT binary patch
literal 570
zcmYk4v2NQi5QcdaWy_LfCuyfn&5*$@TB7J`8||7QNYPCwYN$HKmLrKODHm{tK8atT
zuf(-LfsS1@lL|6~ie<+R86d|1
z1%^1lAx1dD7!w??lZ-324G2Mm#DExjFg*;ih}4LPiGAjlo56#2ye%E5*>e}^R++rh#)&%bHZHW~y0MP0J3=|GzB}Gf
zuarwGy)KKqS{+A%dRMt&XLbt9A1=D7v^HJ^wMI96Tx(a|zE$sBkR!Ul?!LLn|EoGL
z8#DH?QYtR-308$}Y-fKl^U`1V(qGDru9a-cTV3VydS7gEQ(qgsRYhmz#|DimYJo_niJoCg2^
literal 0
HcmV?d00001
diff --git a/final_task/pycalc/__pycache__/main.cpython-36.pyc b/final_task/pycalc/__pycache__/main.cpython-36.pyc
index 83496fd7a1f91edc4acb362330771bc955d8739d..525cb8c1b0eec87a6421f7ac257650541371297d 100644
GIT binary patch
literal 4960
zcmZ`-U2I%O6`q;~Jk&Ca#6Kfb%3
zJ0`YuFFb4jrw_z{^Q-MKSo
z&YYP!bI$qB+^?0(#gDIla_e6UjQyP*`Z=h-h$p#&LNduati@}>)SQ}Q-fqpsTXei-
z;&3|tdQb~Ei^8ZN-S<*3qUt6YxB(tTbVm;45+mOsNh
zY^lm~ehx*YaW`tTSJs<}uD7G4DsoSCH)EMQ^*c#}6EA)~o&e9wc#`)}XqK`*m%J_1
zgcLW>YH{iGIcIAu<1)yE7A?_dnX}c=4)MOiZvXI>$lT0JJ?UUvFLhdOpW)40TzlG2
zSt_JE!&3LBVh$td&(X@n#?u(%Va$Du2~v;fhUSCzG-zR;5#=UJX^Y{KqJ`&dpFjB-
z)%N+>eO~?SzxY)PxzmZ_+^_d~5w_{w(Dg<;FGTU?dZg+)%EM-|60P_2cJ8fqx^fiZtnEDy{exVqphBblBC&%Bvdv#U<2hxxd%N$p4W_Jv;|sS>0dE*iWc$R
z#k<}0XfbZKyPf*twe7~;x>~=cx~-_8lf`exQbo(;61n>&H2nBxz}q)bB!beOuvNiJhQGtkQAk(7TQS=cu
zPATVRalYXA{Vq?vIi@|VRH)xli~2wzZHlCGKrvbcPwH6O47mD`k?b9`wSORI4wgXD
zh;L?8ze4sg2moHuEC6L2wJL%
zMWB&k8S_I7GUn&O{1`;~OEvM-MHNCq&FOU4Y90y@C?-}NRl-Y6QBkIXJRLzaXlyDK
z#X289h!iUw1X;tNPJ=5Sv!T~WBOgv^3g(=K%NF_0qe+C|fq=AdrPGD?Coe1<;yQJ=3++FR|*ADH!u-e>O
zA-Ty{&^_4wlYEx@V&~N7cR%7D1u_clH1iD_PBOMj7MBn_U<@wy+%Bqlj&lVCDD{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b4BiK7I~fpFmpiWNYF}6I6-%ATg8+DMXz*?e2^yQy3CReDfj7r^
zehj*gSRqM|h^(BJ$3AS|&F#Zb?>`k+w#=>FtQHq)xqaC0Dcx;94r)br=ddS_x>0V)
zw#rM$c3-dDl=!ZyV0)3o2$LIuZ`oLakJblUKxLb9?3c?1}~ZTz%smw{`9tJ;LcuzPpF?l
zrnweWi|?)$-hB(iBG|Uk%e`Ko-b+2D?hs>(DhjDw>}ixJ7ttUWG1_jV-X(68sv0T^
zEWN+e>cxppRGr9li5G@iryk|^g~?33+LW3YtzO!ii6!%R@NO4I+NS4SLI6M!WBy{z
Un#2=w5u1u{c{Q)@z2mk24_1JHUH||9
diff --git a/final_task/pycalc/__pycache__/stack.cpython-36.pyc b/final_task/pycalc/__pycache__/stack.cpython-36.pyc
index e728331c34e4e805dbeba30de868055932f2ea99..44749858e0f10c61ea374c11f536381bf48c8609 100644
GIT binary patch
literal 912
zcmaJng^3gv-u?MIw88G0_C@XKwz`JEbKf(BR
zdFY*?*ke?RjXAKf2OPX-Huk}X0Bryr=%VdF4??tE=tG3I2RnG*Zr!=9WHL*Th+Aao
z+6xpLp?Y9TCXfgo=GQ}B4}?n)BCS+zF%Vdl-M=yu;Nj1!cv9vnF49?<$@pfGOr*(g
zOgU9aW#jV#j7sDCw2+yoq@A^0y+~x1#Fprc^r8+CqDU(th>j)2_|u*PA8oe&roCiS
zq&}mb5p6^HXsExAX`?#$TZgF?D%aJ5{(b;$wi1Vr`(#O6fA-NKpebMS73bS7c@D1b
zO087^L(jq10d?#rc%bKY65>4@;HasP!r!W+!EA@pfUedUSwlEreMWta`O$WW&&s6bW8v~m@sl67+x)KUs4?~(~A#)`}9SM<_Fwe-}72ay_^`vSmk
Btd{@)
literal 759
zcmZutJ8#=C5I$0}q^Ne#CR?YD^%4zTiy%dTbQ1zNlMsL)M7nfW
z$t(9F*s0%`ENq=>kKO0coqK_
z;F7f!y6*bn9ZpzUDX>!(^83?K!%I7#$1V|~k+l}Wr9#xL+EsL)3h`qntFhy$44LuP
q%#?0~dX&6zS|x=yo*-coCy}9-9Fu`7x)WaS&?u6
diff --git a/final_task/pycalc/check_mistakes.py b/final_task/pycalc/check_mistakes.py
new file mode 100644
index 00000000..f2dd5688
--- /dev/null
+++ b/final_task/pycalc/check_mistakes.py
@@ -0,0 +1,82 @@
+from pycalc.main import Stack
+from pycalc.consts import *
+
+
+def check_mistakes(expression, functions):
+
+ def is_number(part):
+ for char in part:
+ if not char.isnumeric() and char != '.':
+ return False
+ return True
+
+ if len(expression) == 0:
+ return "ERROR: empty expression!"
+
+ brackets_stack = Stack.Stack()
+ for element in expression:
+ if element == '(':
+ brackets_stack.push('(')
+ elif element == ')':
+ if brackets_stack.is_empty():
+ return "ERROR: brackets are not paired"
+
+ brackets_stack.pop()
+ elif element == " ":
+ expression.remove(element)
+ if not brackets_stack.is_empty():
+ return "ERROR: brackets are not paired"
+
+ if expression[len(expression) - 1] in signs:
+ return "ERROR: no number after operator"
+
+ main_sign_count = 0
+ l_sign_count = 0
+ number_count = 0
+ logical_sign_pos = 0
+
+ for index in range(len(expression)):
+
+ if expression[index] in ['+', '-']:
+ main_sign_count += 1
+
+ elif expression[index] in ['*', '/', '^', '%', '//']:
+ if number_count == 0:
+ return "ERROR: no numbers before sign"
+
+ if index != len(expression) - 1 and expression[index + 1] in ['*', '/', '^', '%', '//']:
+ return "ERROR: duplicate multiply or div sign"
+
+ elif expression[index] in logical_signs:
+ l_sign_count += 1
+ logical_sign_pos = index
+ if l_sign_count > 1:
+ return "ERROR: more than one logical operator"
+
+ elif expression[index] == '=':
+ return "ERROR: illegal usage '='"
+
+ elif is_number(expression[index]):
+ number_count += 1
+ if index != len(expression) - 1 and is_number(expression[index + 1]):
+ return "ERROR: no sign between expression"
+
+ elif expression[index].isalpha():
+ if expression[index] in math_consts:
+ number_count += 1
+ elif expression[index] in functions:
+ if index == len(expression) - 1 or expression[index + 1] != '(':
+ return "ERROR: no brackets after function"
+
+ else:
+ return "ERROR: function does not exist"
+
+ if l_sign_count == 1:
+ if (len(expression[:logical_sign_pos])) == 0 or (len(expression[logical_sign_pos:])) == 0 \
+ or logical_sign_pos in [0, len(expression) - 1]:
+ return "ERROR: one of expressions around logical operator is empty"
+
+ if number_count == 0:
+ return "ERROR: no numbers in expression"
+
+ return ''
diff --git a/final_task/pycalc/consts.py b/final_task/pycalc/consts.py
new file mode 100644
index 00000000..c1628179
--- /dev/null
+++ b/final_task/pycalc/consts.py
@@ -0,0 +1,32 @@
+import operator
+import math
+
+signs = ['+', '-', '*', '/', '^', '%', '>', '<', '=', '//', '!']
+
+logical_signs = {
+ '>': operator.gt,
+ '>=': operator.ge,
+ '==': operator.eq,
+ '!=': operator.ne,
+ "<=": operator.le,
+ "<": operator.le
+}
+
+
+operators_type1 = {
+ '*': operator.mul,
+ '/': operator.truediv,
+ '//': operator.floordiv,
+ '%': operator.mod
+}
+
+operators_main = {
+ '+': operator.add,
+ '-': operator.sub
+}
+
+math_consts = {
+ "pi": math.pi,
+ "e": math.e
+
+}
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 96244e1e..e8cc0a9e 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -1,38 +1,8 @@
import pycalc.stack as Stack
import importlib
-import operator
-import math
import re
-
-signs = ['+', '-', '*', '/', '^', '%', '>', '<', '=', '//', '!']
-
-logical_signs = {
- '>': operator.gt,
- '>=': operator.ge,
- '==': operator.eq,
- '!=': operator.ne,
- "<=": operator.le,
- "<": operator.le
-}
-
-
-operators_type1 = {
- '*': operator.mul,
- '/': operator.truediv,
- '//': operator.floordiv,
- '%': operator.mod
-}
-
-operators_main = {
- '+': operator.add,
- '-': operator.sub
-}
-
-math_consts = {
- "pi": math.pi,
- "e": math.e
-
-}
+from pycalc.consts import *
+from pycalc.check_mistakes import check_mistakes
functions = {'round': round, 'abs': abs}
@@ -55,92 +25,6 @@ def get_args(expression):
return result
-def check_mistakes(expression):
-
- def is_number(part):
- for char in part:
- if not char.isnumeric() and char != '.':
- return False
- return True
-
- if len(expression) == 0:
- print("ERROR: empty expression!")
- return False
-
- brackets_stack = Stack.Stack()
- for element in expression:
- if element == '(':
- brackets_stack.push('(')
- elif element == ')':
- if brackets_stack.is_empty():
- print("ERROR: brackets are not paired")
- return False
- brackets_stack.pop()
- elif element == " ":
- expression.remove(element)
- if not brackets_stack.is_empty():
- print("ERROR: brackets are not paired")
- return False
-
- if expression[len(expression) - 1] in signs:
- print("ERROR: no number after operator")
- return False
-
- main_sign_count = 0
- l_sign_count = 0
- number_count = 0
- logical_sign_pos = 0
-
- for index in range(len(expression)):
-
- if expression[index] in ['+', '-']:
- main_sign_count += 1
-
- elif expression[index] in ['*', '/', '^', '%', '//']:
- if number_count == 0:
- print("ERROR: no numbers before sign")
- return False
- if index != len(expression) - 1 and expression[index + 1] in ['*', '/', '^', '%', '//']:
- print("ERROR: duplicate multiply or div sign")
- return False
-
- elif expression[index] in logical_signs:
- l_sign_count += 1
- logical_sign_pos = index
- if l_sign_count > 1:
- print("ERROR: more than one logical operator")
- return False
- elif expression[index] == '=':
- print("ERROR: illegal usage '='")
- return False
-
- elif is_number(expression[index]):
- number_count += 1
- if index != len(expression) - 1 and is_number(expression[index + 1]):
- print("ERROR: no sign between expression")
-
- elif expression[index].isalpha():
- if expression[index] in math_consts:
- number_count += 1
- elif expression[index] in functions:
- if index == len(expression) - 1 or expression[index + 1] != '(':
- print("ERROR: no brackets after function")
- return False
- else:
- print("ERROR: function does not exist")
- return False
-
- if l_sign_count == 1:
- if (len(expression[:logical_sign_pos])) == 0 or (len(expression[logical_sign_pos:])) == 0:
- print("ERROR: one of expressions around logical operator is empty")
- return False
- if number_count == 0:
- print("ERROR: no numbers in expression")
- return False
-
- return True
-
-
def separate(expression): # separates expression to logical parts
def check_log10():
@@ -277,10 +161,9 @@ def calc(expression):
element = functions[func](*temp) # processing function with 1 or more args
else:
element = functions[func]() # processing function with no args
-
func = ''
except TypeError:
- print("ERROR: wrong amount of arguments for " + func + "(..)")
+ return "ERROR: wrong amount of arguments for " + func + "(..)"
exit()
else:
element = float(calc(expression[begin + 1:end])) # if no function, just a brackets
@@ -390,7 +273,8 @@ def pycalc(expression, modules=list()):
for char in expression:
if char != ' ':
new += char
- if check_mistakes(separate(expression)): # handling some mistakes
+ error = check_mistakes(separate(expression), functions)
+ if error == "": # handling some mistakes
expression = separate(new) # separating expression (look separate function)
for index, element in enumerate(expression): # looking for logical signs
if element in logical_signs:
@@ -399,3 +283,5 @@ def pycalc(expression, modules=list()):
return logical_signs[element](left, right)
result = float(calc(expression)) # start counting
return result
+ else:
+ return error
diff --git a/final_task/pycalc/start.py b/final_task/pycalc/start.py
index 847a6484..92031d4f 100644
--- a/final_task/pycalc/start.py
+++ b/final_task/pycalc/start.py
@@ -7,13 +7,13 @@ def main():
parser.add_argument("EXPRESSION", type=str, help='expression string to evaluate')
parser.add_argument('-m MODULE[MODULE...]', '--use-modules MODULE[MODULE...]', nargs='*',
help='additional modules to use', dest='modules', type=str, default=['math'])
- args = parser.parse_args()
+ args = parser.parse_args(["1+2*3=="])
answer = Main.pycalc(args.EXPRESSION, args.modules)
if type(answer) == float or type(answer) == int:
if answer % 1 == 0:
- print(int(answer))
+ return int(answer)
else:
- print(answer)
- elif type(answer) == bool:
- print(answer)
+ return answer
+ else:
+ return answer
diff --git a/final_task/pycalc/test_main.py b/final_task/pycalc/test_main.py
new file mode 100644
index 00000000..c4d4d98d
--- /dev/null
+++ b/final_task/pycalc/test_main.py
@@ -0,0 +1,36 @@
+import pycalc.main as mn
+import unittest
+import math as m
+
+
+class TestFunctions(unittest.TestCase):
+
+ def test_error(self):
+ self.assertEqual()
+
+ def test_solve_equality(self):
+
+
+ def test_add_math_objects(self):
+
+
+ def test_multiply(self):
+
+
+ def test_get_degree(self):
+
+
+ def test_number_sign(self):
+
+
+ def test_search_float(self):
+
+
+ def test_skip_space(self):
+
+
+ def test_get_bracket(self):
+
+
+ def test_get_func_arguments(self):
+
From fd06e507d1799c2a04bf6a99e9268eec53f4d332 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 11:12:01 +0300
Subject: [PATCH 55/73] Bug fixes
From 6e6b4754455ca4d27c9bed77db2cbd78ad635f91 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 11:16:02 +0300
Subject: [PATCH 56/73] Add files via upload
---
final_task/pycalc/start.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/final_task/pycalc/start.py b/final_task/pycalc/start.py
index 92031d4f..63e68cfc 100644
--- a/final_task/pycalc/start.py
+++ b/final_task/pycalc/start.py
@@ -7,13 +7,13 @@ def main():
parser.add_argument("EXPRESSION", type=str, help='expression string to evaluate')
parser.add_argument('-m MODULE[MODULE...]', '--use-modules MODULE[MODULE...]', nargs='*',
help='additional modules to use', dest='modules', type=str, default=['math'])
- args = parser.parse_args(["1+2*3=="])
-
+ args = parser.parse_args()
answer = Main.pycalc(args.EXPRESSION, args.modules)
if type(answer) == float or type(answer) == int:
if answer % 1 == 0:
- return int(answer)
+ print(int(answer))
else:
- return answer
+ print(answer)
else:
- return answer
+ print(answer)
+
From c647660946f6829a06e5ce6bad739f0e7b237fe1 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 11:36:02 +0300
Subject: [PATCH 57/73] Fixed
---
.../pycalc/__pycache__/main.cpython-36.pyc | Bin 4960 -> 5059 bytes
final_task/pycalc/main.py | 21 ++++++++++++++----
final_task/pycalc/test_main.py | 20 ++++++++---------
3 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/final_task/pycalc/__pycache__/main.cpython-36.pyc b/final_task/pycalc/__pycache__/main.cpython-36.pyc
index 525cb8c1b0eec87a6421f7ac257650541371297d..2dffc40a02cefafd1019fb7f0225917b0e0fc585 100644
GIT bin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:38:02 +0300
Subject: [PATCH 58/73] PEP8 fix
---
final_task/pycalc/start.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/final_task/pycalc/start.py b/final_task/pycalc/start.py
index 63e68cfc..4f34429f 100644
--- a/final_task/pycalc/start.py
+++ b/final_task/pycalc/start.py
@@ -16,4 +16,3 @@ def main():
print(answer)
else:
print(answer)
-
From 89624e477f159bfcb15470d0f12ec6298f1a7fd2 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 15:13:06 +0300
Subject: [PATCH 59/73] Bug fixed. UnitTests in process
---
.../pycalc/__pycache__/main.cpython-36.pyc | Bin 5059 -> 5077 bytes
final_task/pycalc/check_mistakes.py | 33 +++++++++++++++---
final_task/pycalc/test_main.py | 9 ++++-
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/final_task/pycalc/__pycache__/main.cpython-36.pyc b/final_task/pycalc/__pycache__/main.cpython-36.pyc
index 2dffc40a02cefafd1019fb7f0225917b0e0fc585..6f29418f6a73077bd69e99cad3e8e8920b343cc5 100644
GIT binary patch
delta 895
zcmZ`%O=uHA6rR~^Hk;jK^V8DSHjS}Kjp?DajoSEwLg_)UCk3rbr7TIBF5Paz%T`<1
zm_zaBW^tt8(W6J{MbDl@uOjThqhL?H3Zl-NMCd^o_~y;`zV|Wn-n=hG*7
zZDsuI8|@3tnsN*3_k(cTv#J|G*mi66?Lcl>;Jqd=%6`)>%^Y+kJ48p>_i#=bC4|5j
zODJC_%*Yy-TaE)rmLwSGTOhAFRzol-i|h}YO4|e5?Q{M5caeuQ$13WR*^_8EiBJ^f
z)pZMC1kb`XBwQhjL;+!p9jUMA{K4~RSym>HnPMN~H|Pu-Hu85*aiS!HgnR|z62fH!
z{V(vFin{-6|KY%xQJ@+2)+kKOq0xB`L5ROBkT)%FJ)m_{YS~c6+&T8kC|*6oLo>Q*
z+3srFZn(TLTW-~qF*f7abi29L7AY7;sorWnsKcrl1dOn1Vp12)>UWGKeo~X|B_DTh
zdJ#XoOFLxyg{S&tmoAcfPgkUl+KKv6FS?=bb{wQ8lHW%CJ%GA&*?ic
zPxm#<-XZRwOuX2J28Wd3^0ixJnFxi>6*^Z8^%Q$l0)stEWpn7sb1|WcVRT#tOYB1`
zqhG^*Cj2IEzgWN`
z*{QF2W*F?ox(7q3KGrO(P+B|Ov#L-++6(McI)6P$2dPA3)S!xldy*t(b2Ermjp3M$ioDmPn;8{EbFCEB^%|8Ts9J@?^d@l#4{s8M!%Par@
delta 886
zcmZ`%&ubGw7@gVdZj#+3P1Dk*B&{{AhSVR$7B!99mbMf@=)oLpL#3=~ek@71;mcGT
z*chRx7Z1gO-aL2|PtuE?y$Id}QTE_b@a7*-)cJO!R8SV)eDmhL$G6|i$MoB@HXROY
zZ1wB+iL3|4h$sUS5>xP)hy`Hx6?_KYYC
z!7anIHkxL|5`)>XijItRA&f&ew|AQE5yVldH@5GUV8gu#7~;jAQ@T5>?!CrEn@Y{
zgoSDve4qqBTg#JG(n@-2JFqDa3eO*hE*t}%W1oWRdHA#5_+l&SS=`{zU$S{mwni*z
zmDr&?vHf`wnkN}$1r~5VD#BTQ)SK1ku=FA1_*^Wm_hK1CnCEw5Q%f_Vbd(ancK1;%
zBO%vIW#%YgR;mmJP{~Q}zkZ7Dns47V`NuyMyF)E1_D_Me@
x!jp*>LZ0iqcLjJU5J9+(FwPhIW+vT!hjE`nz)nRsrg#UKajcE*t-b7<_yvrB$p8QV
diff --git a/final_task/pycalc/check_mistakes.py b/final_task/pycalc/check_mistakes.py
index f2dd5688..d9a8eb5e 100644
--- a/final_task/pycalc/check_mistakes.py
+++ b/final_task/pycalc/check_mistakes.py
@@ -2,7 +2,7 @@
from pycalc.consts import *
-def check_mistakes(expression, functions):
+def check_mistakes(expression, functions, mode=0):
def is_number(part):
for char in part:
@@ -11,17 +11,35 @@ def is_number(part):
return True
if len(expression) == 0:
- return "ERROR: empty expression!"
-
+ if mode == 0:
+ return "ERROR: empty expression"
+ elif mode == 1:
+ return "ERROR: empty brackets"
+ elif mode == 2:
+ return ''
+
+ begin = -1
brackets_stack = Stack.Stack()
- for element in expression:
+
+ for index, element in enumerate(expression):
if element == '(':
brackets_stack.push('(')
+ if begin == -1:
+ begin = index
elif element == ')':
if brackets_stack.is_empty():
return "ERROR: brackets are not paired"
-
brackets_stack.pop()
+ if brackets_stack.is_empty():
+ if expression[begin-1].isalpha() and not expression[begin-1] in math_consts:
+ error = check_mistakes(expression[begin + 1: index], functions, 2)
+ else:
+ error = check_mistakes(expression[begin + 1: index], functions, 1)
+ begin = -1
+
+ if error != '':
+ return error
+
elif element == " ":
expression.remove(element)
if not brackets_stack.is_empty():
@@ -71,6 +89,11 @@ def is_number(part):
else:
return "ERROR: function does not exist"
+ elif expression[index] == '(':
+ if expression[index - 1] not in functions and expression[index - 1] not in signs \
+ and index != 0:
+ return "ERROR: no sign or function before brackets"
+
if l_sign_count == 1:
if (len(expression[:logical_sign_pos])) == 0 or (len(expression[logical_sign_pos:])) == 0 \
or logical_sign_pos in [0, len(expression) - 1]:
diff --git a/final_task/pycalc/test_main.py b/final_task/pycalc/test_main.py
index 1c0b0cbc..0c314cf7 100644
--- a/final_task/pycalc/test_main.py
+++ b/final_task/pycalc/test_main.py
@@ -6,7 +6,14 @@
class TestFunctions(unittest.TestCase):
def test_error(self):
- pass
+ self.assertEqual(mn.pycalc(''), "ERROR: empty expression")
+ self.assertEqual(mn.pycalc('123-'), "ERROR: no number after operator")
+ self.assertEqual(mn.pycalc('123-()'), "ERROR: empty brackets")
+ self.assertEqual(mn.pycalc('123-(-)'), "ERROR: no number after operator")
+ self.assertEqual(mn.pycalc('func()'), "ERROR: function does not exist")
+ self.assertEqual(mn.pycalc('pow(12, 12, 3)'), "ERROR: wrong amount of arguments for pow(..)")
+ self.assertEqual(mn.pycalc('123+23*(12 - 23 + 12))'), "ERROR: brackets are not paired")
+ self.assertEqual(mn.pycalc('123+23*(12 - 23(12))'), "ERROR: no sign or function before brackets")
def test_solve_equality(self):
pass
From 61c8a1114bd700a030a70b9e627496452c335857 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 17:08:07 +0300
Subject: [PATCH 60/73] Uploaded tests
---
.../__pycache__/check_mistakes.cpython-36.pyc | Bin 1964 -> 2380 bytes
.../pycalc/__pycache__/main.cpython-36.pyc | Bin 5077 -> 5195 bytes
final_task/pycalc/check_mistakes.py | 6 +-
final_task/pycalc/main.py | 18 ++--
final_task/pycalc/test_main.py | 82 ++++++++++--------
5 files changed, 59 insertions(+), 47 deletions(-)
diff --git a/final_task/pycalc/__pycache__/check_mistakes.cpython-36.pyc b/final_task/pycalc/__pycache__/check_mistakes.cpython-36.pyc
index ae221052888e642e6b62212ffd9f1aab9803eb58..d9c2dc83790670b50198ae98c96be9eb909f0a7e 100644
GIT binary patch
literal 2380
zcmah}%WoS+7@ygfAF%@znn$7Srlb#-5+68#sp{E{zzXWmSQ0)~7DLo?&J^;U&wG*eUgrjfr?f3qE-#7C?wOV$6`1Afh
zRYLwCGd~mjEs(r~gAqnU(xsb}D&7c?Wx>hp;6zn%T|7^E+VZ
zRbK^CKO`Up(5E1|0V$)*cua<7LQ*oK%adVHbv0T4cqJspF#)T}=hGHBz!$N(-vmhmCtjRmdy4HZnm-SCf=G4*Wl1RUlyw
zOQ14n4pcdydp{;~xwXRNfIj$k=%7w#nXq@Y-`8o0*&mW&>3}}mo@iFJ=C>3vG%`=v
zX&~YpXGO(^c&@COy$D3uMR-8M7MjR0jgwS#oWIht&QJ#46~%WfZM)bc(chDdOUPpg
zhb<$Inaf5LlG~_3RX6vF?Ak8RuWg^RGl=*!_f|84|1bF$CZy^Mr_rMIT%J-be|jQ1
zDv?i=e$rb>cl#528__NH4$fP-x7sTpuTjf41MvzcC74bwae$?o^ENx1V}z+HEQ|wF
z+)~Igl2+8-@1=uHC+i+gl1`)bDZ;
z_%$Q5dY(u!%Wr$)XCjJ-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`~17dP#6%$K0mgi;HHVa+EzMvg3%^LEHtO
zV4;Y6=M8&7z`CFt2&c>J+xKpdw&s1QC!dHEs}-pE!LNz2H}^0VtyI6hLO|F-%-G-
z+ODW=?SE8DnHI2!t49HYJP^Iif|<$ZBh!*N$xP0|_yx-h#gfPj?nGUdEth0>3bf)0
zCrEluwiG(D*Ky-WNYSWewfTr;)fq=Z{iUG8l^LfUm~q$7DlA|ji{#;@(D9-?Fa#O^
zP!BGgiiswp2Xw9o1+-
h{c?#E%;km)9jLd?^ERxzVN3@B+f&a_=&(V_+Q0r!67c{4
diff --git a/final_task/pycalc/__pycache__/main.cpython-36.pyc b/final_task/pycalc/__pycache__/main.cpython-36.pyc
index 6f29418f6a73077bd69e99cad3e8e8920b343cc5..8667c1ccd130afc7e3742647ba2e37b4870423d2 100644
GIT binary patch
delta 1950
zcmZ`)-ESL35Z~SVc5NqdLefGhp%HB?Xh`S>Eh-4{O+Nxss-{#a=HgpBSKDW2ZbMUa
zmW5JysDwm&54`Zm13aRN{{g`>59})fsW1EieSw+1&_)Ps`RBRanc3Ny-^~4T^ym4x
z8e
zePU#zrh~uN$zmBH;u-6BP|MhLly^91+ov-22D`Q}EWo`FDwNZDq8x96CiF6S627OT7cwJYP3%SwjM_XN~
zttbZVwWSJ`0v)urlBSCLNm{qHSE!`g-PH|l^r4du!lu-A687YG3?}lw`0~**+Bd>(
zw?XD5x>p&237?nDx5{A>pYQyj9q>@dzvAakXnO$iW9_6WY<9F0Cz0I7wGb3cpiTib
zl(cW$Lpz)c$_>uO+e>inD?F88ROP?
z+}GTY%}&FZ%;&T2_ZP_#aD)f^SvY|IyH2zKsl66Phxaov)df6<``T`G!}gvigI2uV
zNaJ>rF6M{4t&@jHsdPE)Zpk+R`cUWEO%=q+uF<1tf;ep?TfKD&XYwDt(<8dW13rtX
zF}dc8nxD~pLGw`aPqhC}jUMn1b%_pasG9@11ka-x%nklM^`N*%0D1o|ao>d>xMlXyLy^na+Xd*pSYO-5*;V>PzK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%t7uzT$4JN!v4^Hvj!WIGda1+(%4qTk!
zE}zAd;1y1^E#MN$*Ji>>VPmD30-6gj1AT$0Wds}@<7K7MOH!4F`8RV%u9=K1kci0$
qwYauBF-{1XeJswuXGMGGixj+y(Xy0gfWo7vA_B{s^;+JD*?$5<(w
Date: Thu, 23 May 2019 17:10:37 +0300
Subject: [PATCH 61/73] PEP8
---
final_task/pycalc/main.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/final_task/pycalc/main.py b/final_task/pycalc/main.py
index 02f9f869..30e8b4a1 100644
--- a/final_task/pycalc/main.py
+++ b/final_task/pycalc/main.py
@@ -4,6 +4,7 @@
from pycalc.consts import *
from pycalc.check_mistakes import check_mistakes
+
functions = {'round': round, 'abs': abs}
From 9d29022f1e19eea94eaf0a8b18b1c26378482fc5 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 17:15:19 +0300
Subject: [PATCH 62/73] PEP8
---
final_task/pycalc/test_main.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/final_task/pycalc/test_main.py b/final_task/pycalc/test_main.py
index aabd945d..f37cee98 100644
--- a/final_task/pycalc/test_main.py
+++ b/final_task/pycalc/test_main.py
@@ -5,6 +5,7 @@
class TestFunctions(unittest.TestCase):
+
def test_check_mistakes(self):
self.assertEqual(check_mistakes([]), "ERROR: empty expression")
self.assertEqual(check_mistakes(['123', '-']), "ERROR: no number after operator")
From 22c1374617ada770471017b9864ef579bf45f657 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 17:57:11 +0300
Subject: [PATCH 63/73] PEP8
---
final_task/pycalc/test_main.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/final_task/pycalc/test_main.py b/final_task/pycalc/test_main.py
index f37cee98..90ad2c47 100644
--- a/final_task/pycalc/test_main.py
+++ b/final_task/pycalc/test_main.py
@@ -5,7 +5,7 @@
class TestFunctions(unittest.TestCase):
-
+
def test_check_mistakes(self):
self.assertEqual(check_mistakes([]), "ERROR: empty expression")
self.assertEqual(check_mistakes(['123', '-']), "ERROR: no number after operator")
From df2c3ed49c5e30e0334581ce2389d66e835c7b4c Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 17:59:36 +0300
Subject: [PATCH 64/73] PEP8
---
final_task/pycalc/test_main.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/final_task/pycalc/test_main.py b/final_task/pycalc/test_main.py
index 90ad2c47..358af1d8 100644
--- a/final_task/pycalc/test_main.py
+++ b/final_task/pycalc/test_main.py
@@ -3,8 +3,8 @@
from pycalc.check_mistakes import check_mistakes
import math as m
-class TestFunctions(unittest.TestCase):
+class TestFunctions(unittest.TestCase):
def test_check_mistakes(self):
self.assertEqual(check_mistakes([]), "ERROR: empty expression")
From 45813ed4edb16e31a01e30a0d64d0d2c0c67fee3 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 18:26:42 +0300
Subject: [PATCH 65/73] Some tests added
---
final_task/pycalc/test_main.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/final_task/pycalc/test_main.py b/final_task/pycalc/test_main.py
index 358af1d8..3c056797 100644
--- a/final_task/pycalc/test_main.py
+++ b/final_task/pycalc/test_main.py
@@ -49,4 +49,5 @@ def test_calc(self):
def test_pycalc(self):
self.assertAlmostEqual(float(mn.pycalc('15+23*cos(17-23)')), 37.08391659295842)
- self.assertEqual(mn.pycalc('round(3.6675)'), '4.0')
+ self.assertEqual(float(mn.pycalc('round(3.6675)')), 4.0)
+ self.assertEqual(mn.pycalc('2^4^2'), 65536)
From dd2512578c0f151d42448e75000d57f932feecf2 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 18:49:35 +0300
Subject: [PATCH 66/73] Add files via upload
---
check_mistakes.py | 106 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
create mode 100644 check_mistakes.py
diff --git a/check_mistakes.py b/check_mistakes.py
new file mode 100644
index 00000000..9f88be21
--- /dev/null
+++ b/check_mistakes.py
@@ -0,0 +1,106 @@
+from pycalc.main import Stack
+from pycalc.consts import *
+
+
+def check_mistakes(expression, functions={}, mode=0):
+
+ def is_number(part):
+ for char in part:
+ if not char.isnumeric() and char != '.':
+ return False
+ return True
+
+ if len(expression) == 0:
+ if mode == 0:
+ return "ERROR: empty expression"
+ elif mode == 1:
+ return "ERROR: empty brackets"
+ elif mode == 2:
+ return ''
+
+ begin = -1
+ brackets_stack = Stack.Stack()
+
+ for index, element in enumerate(expression):
+ if element == '(':
+ brackets_stack.push('(')
+ if begin == -1:
+ begin = index
+ elif element == ')':
+ if brackets_stack.is_empty():
+ return "ERROR: brackets are not paired"
+ brackets_stack.pop()
+ if brackets_stack.is_empty():
+ if expression[begin - 1].isalpha() and not expression[begin - 1] in math_consts:
+ error = check_mistakes(expression[begin + 1: index], functions, 2)
+ else:
+ error = check_mistakes(expression[begin + 1: index], functions, 1)
+ begin = -1
+
+ if error != '':
+ return error
+
+ elif element == " ":
+ expression.remove(element)
+ if not brackets_stack.is_empty():
+ return "ERROR: brackets are not paired"
+
+ if expression[len(expression) - 1] in signs:
+ return "ERROR: no number after operator"
+
+ main_sign_count = 0
+ l_sign_count = 0
+ number_count = 0
+ logical_sign_pos = 0
+
+ for index in range(len(expression)):
+
+ if expression[index] in ['+', '-']:
+ main_sign_count += 1
+
+ elif expression[index] in ['*', '/', '^', '%', '//']:
+ if number_count == 0:
+ return "ERROR: no numbers before sign"
+
+ if index != len(expression) - 1 and expression[index + 1] in ['*', '/', '^', '%', '//']:
+ return "ERROR: duplicate multiply or div sign"
+
+ elif expression[index] in logical_signs:
+ l_sign_count += 1
+ logical_sign_pos = index
+ if l_sign_count > 1:
+ return "ERROR: more than one logical operator"
+
+ elif expression[index] == '=':
+ return "ERROR: illegal usage '='"
+
+ elif is_number(expression[index]):
+ number_count += 1
+ if index != len(expression) - 1 and is_number(expression[index + 1]):
+ return "ERROR: no sign between expression"
+
+ elif expression[index].isalpha():
+ if expression[index] in math_consts:
+ number_count += 1
+ elif expression[index] in functions:
+ if index == len(expression) - 1 or expression[index + 1] != '(':
+ return "ERROR: no brackets after function"
+ number_count += 1
+
+ else:
+ return "ERROR: function does not exist"
+
+ elif expression[index] == '(':
+ if expression[index - 1] not in functions and expression[index - 1] not in signs \
+ and index != 0:
+ return "ERROR: no sign or function before brackets"
+
+ if l_sign_count == 1:
+ if (len(expression[:logical_sign_pos])) == 0 or (len(expression[logical_sign_pos:])) == 0 \
+ or logical_sign_pos in [0, len(expression) - 1]:
+ return "ERROR: one of expressions around logical operator is empty"
+
+ if number_count == 0:
+ return "ERROR: no numbers in expression"
+
+ return ''
From 214cdacbd2fbe49ed757391566984d84597a45da Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 18:50:02 +0300
Subject: [PATCH 67/73] Delete check_mistakes.py
---
check_mistakes.py | 106 ----------------------------------------------
1 file changed, 106 deletions(-)
delete mode 100644 check_mistakes.py
diff --git a/check_mistakes.py b/check_mistakes.py
deleted file mode 100644
index 9f88be21..00000000
--- a/check_mistakes.py
+++ /dev/null
@@ -1,106 +0,0 @@
-from pycalc.main import Stack
-from pycalc.consts import *
-
-
-def check_mistakes(expression, functions={}, mode=0):
-
- def is_number(part):
- for char in part:
- if not char.isnumeric() and char != '.':
- return False
- return True
-
- if len(expression) == 0:
- if mode == 0:
- return "ERROR: empty expression"
- elif mode == 1:
- return "ERROR: empty brackets"
- elif mode == 2:
- return ''
-
- begin = -1
- brackets_stack = Stack.Stack()
-
- for index, element in enumerate(expression):
- if element == '(':
- brackets_stack.push('(')
- if begin == -1:
- begin = index
- elif element == ')':
- if brackets_stack.is_empty():
- return "ERROR: brackets are not paired"
- brackets_stack.pop()
- if brackets_stack.is_empty():
- if expression[begin - 1].isalpha() and not expression[begin - 1] in math_consts:
- error = check_mistakes(expression[begin + 1: index], functions, 2)
- else:
- error = check_mistakes(expression[begin + 1: index], functions, 1)
- begin = -1
-
- if error != '':
- return error
-
- elif element == " ":
- expression.remove(element)
- if not brackets_stack.is_empty():
- return "ERROR: brackets are not paired"
-
- if expression[len(expression) - 1] in signs:
- return "ERROR: no number after operator"
-
- main_sign_count = 0
- l_sign_count = 0
- number_count = 0
- logical_sign_pos = 0
-
- for index in range(len(expression)):
-
- if expression[index] in ['+', '-']:
- main_sign_count += 1
-
- elif expression[index] in ['*', '/', '^', '%', '//']:
- if number_count == 0:
- return "ERROR: no numbers before sign"
-
- if index != len(expression) - 1 and expression[index + 1] in ['*', '/', '^', '%', '//']:
- return "ERROR: duplicate multiply or div sign"
-
- elif expression[index] in logical_signs:
- l_sign_count += 1
- logical_sign_pos = index
- if l_sign_count > 1:
- return "ERROR: more than one logical operator"
-
- elif expression[index] == '=':
- return "ERROR: illegal usage '='"
-
- elif is_number(expression[index]):
- number_count += 1
- if index != len(expression) - 1 and is_number(expression[index + 1]):
- return "ERROR: no sign between expression"
-
- elif expression[index].isalpha():
- if expression[index] in math_consts:
- number_count += 1
- elif expression[index] in functions:
- if index == len(expression) - 1 or expression[index + 1] != '(':
- return "ERROR: no brackets after function"
- number_count += 1
-
- else:
- return "ERROR: function does not exist"
-
- elif expression[index] == '(':
- if expression[index - 1] not in functions and expression[index - 1] not in signs \
- and index != 0:
- return "ERROR: no sign or function before brackets"
-
- if l_sign_count == 1:
- if (len(expression[:logical_sign_pos])) == 0 or (len(expression[logical_sign_pos:])) == 0 \
- or logical_sign_pos in [0, len(expression) - 1]:
- return "ERROR: one of expressions around logical operator is empty"
-
- if number_count == 0:
- return "ERROR: no numbers in expression"
-
- return ''
From cd0a9e1c0db8a157a83b1d543e9602f56cff8c3f Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 18:50:14 +0300
Subject: [PATCH 68/73] Add files via upload
---
test_main.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100644 test_main.py
diff --git a/test_main.py b/test_main.py
new file mode 100644
index 00000000..3c056797
--- /dev/null
+++ b/test_main.py
@@ -0,0 +1,53 @@
+import pycalc.main as mn
+import unittest
+from pycalc.check_mistakes import check_mistakes
+import math as m
+
+
+class TestFunctions(unittest.TestCase):
+
+ def test_check_mistakes(self):
+ self.assertEqual(check_mistakes([]), "ERROR: empty expression")
+ self.assertEqual(check_mistakes(['123', '-']), "ERROR: no number after operator")
+ self.assertEqual(check_mistakes(['123', '-', '(', ')']), "ERROR: empty brackets")
+ self.assertEqual(check_mistakes(['123', '-', '(', '-', ')']), "ERROR: no number after operator")
+ self.assertEqual(check_mistakes(['func', '(', ')']), "ERROR: function does not exist")
+ self.assertEqual(check_mistakes(['123', '+', '23', '*', '(', '12', '-', '23', '+', '12', ')', ')']),
+ "ERROR: brackets are not paired")
+ self.assertEqual(check_mistakes(['123', '+', '23', '*', '(', '12', '-', '23', '(', '12', ')', ')']),
+ "ERROR: no sign or function before brackets")
+ self.assertEqual(check_mistakes(['123', '+', '23', '/', ' ', '/', '(', '12', '-', '3', ')']),
+ "ERROR: duplicate multiply or div sign")
+
+ def test_get_args(self):
+ self.assertEqual(mn.get_args(['12', ',', 'pi', ',', '12', '+', '32', ',', '43', '*', '2']), [12, m.pi, 44, 86])
+
+ def test_separate(self):
+ self.assertEqual(mn.separate(''), [])
+ self.assertEqual(mn.separate("123-5"), ['123', '-', '5'])
+ self.assertEqual(mn.separate("123-(7)"), ['123', '-', '(', '7', ')'])
+ self.assertEqual(mn.separate("12-(-)"), ['12', '-', '(', '-', ')'])
+ self.assertEqual(mn.separate("func()"), ['func', '(', ')'])
+ self.assertEqual(mn.separate("123+23*(12-23+12)"),
+ ['123', '+', '23', '*', '(', '12', '-', '23', '+', '12', ')'])
+ self.assertEqual(mn.separate("123+23*(12-23(12))"),
+ ['123', '+', '23', '*', '(', '12', '-', '23', '(', '12', ')', ')'])
+ self.assertEqual(mn.separate("123+23/ /(12^3)"),
+ ['123', '+', '23', '/', '/', '(', '12', '^', '3', ')'])
+ self.assertEqual(mn.separate("log10(123) + --- 23"),
+ ['log10', '(', '123', ')', '+', '---', '23'])
+
+ def test_calc(self):
+ self.assertEqual(mn.calc(["10"]), '10.0')
+ self.assertEqual(mn.calc(['123', '-', '10']), '113.0')
+ self.assertEqual(mn.calc(['123', '-', '(', '10', '+', '7', ')']), '106.0')
+ self.assertEqual(mn.calc(['2', '^', '(', '5', '-', '7', ')']), '0.25')
+ self.assertEqual(mn.calc(['123', '/', '23', '*', '(', '12', '-', '23', '^', '2', ')']),
+ "-2764.8260869565215")
+ self.assertEqual(mn.calc(['15', '+', '23', '//', '(', '17', '-', '23', ')']),
+ "11.0")
+
+ def test_pycalc(self):
+ self.assertAlmostEqual(float(mn.pycalc('15+23*cos(17-23)')), 37.08391659295842)
+ self.assertEqual(float(mn.pycalc('round(3.6675)')), 4.0)
+ self.assertEqual(mn.pycalc('2^4^2'), 65536)
From 80d1571bfa35cc0c90d5d7ab71bd915fb38d8992 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 18:50:23 +0300
Subject: [PATCH 69/73] Update .travis.yml
---
.travis.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.travis.yml b/.travis.yml
index 72c3331d..2086a957 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,4 +9,5 @@ script:
- nosetests --cover-branches --with-coverage .
- pycodestyle --ignore=W605 --max-line-length=120 .
- python ./../pycalc_checker.py
+ - python ./../test_main.py
- cd -
From f5a28ef56f87b7ad0aefd6edf5e00b70d7df90cb Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 23:03:32 +0300
Subject: [PATCH 70/73] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=8B=D1=82=D0=BA?=
=?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B8=D1=82=D1=8C?=
=?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?=
=?UTF-8?q?=D0=B8=D0=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test_main.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test_main.py b/test_main.py
index 3c056797..84933af4 100644
--- a/test_main.py
+++ b/test_main.py
@@ -1,6 +1,6 @@
-import pycalc.main as mn
+import final_task.pycalc.main as mn
import unittest
-from pycalc.check_mistakes import check_mistakes
+from final_task.pycalc.check_mistakes import check_mistakes
import math as m
From 86faab3c1ce0dae1f3fbd3bf67e452ba98a910de Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 23:06:55 +0300
Subject: [PATCH 71/73] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE?=
=?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BD=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=83?=
=?UTF-8?q?=D1=87=D0=B8=D0=BB=D0=BE=D1=81=D1=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test_main.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test_main.py b/test_main.py
index 84933af4..3c056797 100644
--- a/test_main.py
+++ b/test_main.py
@@ -1,6 +1,6 @@
-import final_task.pycalc.main as mn
+import pycalc.main as mn
import unittest
-from final_task.pycalc.check_mistakes import check_mistakes
+from pycalc.check_mistakes import check_mistakes
import math as m
From 752abc8832d425a450db806e47df297914a8c417 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 23:14:38 +0300
Subject: [PATCH 72/73] Update .travis.yml
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 2086a957..44e4ab99 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,5 +9,5 @@ script:
- nosetests --cover-branches --with-coverage .
- pycodestyle --ignore=W605 --max-line-length=120 .
- python ./../pycalc_checker.py
- - python ./../test_main.py
+ - python ./test_main.py
- cd -
From cee624360327a9f42bff977eab6e458a98671961 Mon Sep 17 00:00:00 2001
From: Andrei Trukhan <44117784+BadMadNobody@users.noreply.github.com>
Date: Thu, 23 May 2019 23:16:42 +0300
Subject: [PATCH 73/73] Create test_main.py
---
final_task/test_main.py | 53 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100644 final_task/test_main.py
diff --git a/final_task/test_main.py b/final_task/test_main.py
new file mode 100644
index 00000000..3c056797
--- /dev/null
+++ b/final_task/test_main.py
@@ -0,0 +1,53 @@
+import pycalc.main as mn
+import unittest
+from pycalc.check_mistakes import check_mistakes
+import math as m
+
+
+class TestFunctions(unittest.TestCase):
+
+ def test_check_mistakes(self):
+ self.assertEqual(check_mistakes([]), "ERROR: empty expression")
+ self.assertEqual(check_mistakes(['123', '-']), "ERROR: no number after operator")
+ self.assertEqual(check_mistakes(['123', '-', '(', ')']), "ERROR: empty brackets")
+ self.assertEqual(check_mistakes(['123', '-', '(', '-', ')']), "ERROR: no number after operator")
+ self.assertEqual(check_mistakes(['func', '(', ')']), "ERROR: function does not exist")
+ self.assertEqual(check_mistakes(['123', '+', '23', '*', '(', '12', '-', '23', '+', '12', ')', ')']),
+ "ERROR: brackets are not paired")
+ self.assertEqual(check_mistakes(['123', '+', '23', '*', '(', '12', '-', '23', '(', '12', ')', ')']),
+ "ERROR: no sign or function before brackets")
+ self.assertEqual(check_mistakes(['123', '+', '23', '/', ' ', '/', '(', '12', '-', '3', ')']),
+ "ERROR: duplicate multiply or div sign")
+
+ def test_get_args(self):
+ self.assertEqual(mn.get_args(['12', ',', 'pi', ',', '12', '+', '32', ',', '43', '*', '2']), [12, m.pi, 44, 86])
+
+ def test_separate(self):
+ self.assertEqual(mn.separate(''), [])
+ self.assertEqual(mn.separate("123-5"), ['123', '-', '5'])
+ self.assertEqual(mn.separate("123-(7)"), ['123', '-', '(', '7', ')'])
+ self.assertEqual(mn.separate("12-(-)"), ['12', '-', '(', '-', ')'])
+ self.assertEqual(mn.separate("func()"), ['func', '(', ')'])
+ self.assertEqual(mn.separate("123+23*(12-23+12)"),
+ ['123', '+', '23', '*', '(', '12', '-', '23', '+', '12', ')'])
+ self.assertEqual(mn.separate("123+23*(12-23(12))"),
+ ['123', '+', '23', '*', '(', '12', '-', '23', '(', '12', ')', ')'])
+ self.assertEqual(mn.separate("123+23/ /(12^3)"),
+ ['123', '+', '23', '/', '/', '(', '12', '^', '3', ')'])
+ self.assertEqual(mn.separate("log10(123) + --- 23"),
+ ['log10', '(', '123', ')', '+', '---', '23'])
+
+ def test_calc(self):
+ self.assertEqual(mn.calc(["10"]), '10.0')
+ self.assertEqual(mn.calc(['123', '-', '10']), '113.0')
+ self.assertEqual(mn.calc(['123', '-', '(', '10', '+', '7', ')']), '106.0')
+ self.assertEqual(mn.calc(['2', '^', '(', '5', '-', '7', ')']), '0.25')
+ self.assertEqual(mn.calc(['123', '/', '23', '*', '(', '12', '-', '23', '^', '2', ')']),
+ "-2764.8260869565215")
+ self.assertEqual(mn.calc(['15', '+', '23', '//', '(', '17', '-', '23', ')']),
+ "11.0")
+
+ def test_pycalc(self):
+ self.assertAlmostEqual(float(mn.pycalc('15+23*cos(17-23)')), 37.08391659295842)
+ self.assertEqual(float(mn.pycalc('round(3.6675)')), 4.0)
+ self.assertEqual(mn.pycalc('2^4^2'), 65536)