diff options
author | PanFritz <redstonenoobpan@gmail.com> | 2015-01-13 13:05:22 +0100 |
---|---|---|
committer | PanFritz <redstonenoobpan@gmail.com> | 2015-01-13 13:05:22 +0100 |
commit | 89c5c3e64606276013cfd4c272fbf688a895ed40 (patch) | |
tree | 486eddc2d4568e75179bdb4558d40313f7cedc96 /calc.py | |
parent | f85a8e1bab9ae7b1a2ae349a710d21f2a185dcd5 (diff) |
Added should_calc check and done expression var
Diffstat (limited to 'calc.py')
-rw-r--r-- | calc.py | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -12,6 +12,7 @@ def calc(text): returns (expression, result) or None """ expression = "" + d_expression = "" should_calc = False for char in text: if char.isdigit() or (should_calc and char in [".", " "]): @@ -22,15 +23,17 @@ def calc(text): expression += char elif char.isalpha(): # don't include any more text in the calculation + if should_calc: + d_expression = expression expression = "" - if should_calc and not any(op in expression for op in ignore_operators): + if should_calc and not any(op in d_expression for op in ignore_operators): try: - result = str(eval(expression)) # pylint: disable = W0123 + result = str(eval(d_expression)) # pylint: disable = W0123 except: # pylint: disable = W0702 # we can run into all kinds of errors here # most probably SyntaxError return None - return (expression, result) + return (d_expression, result) return None |