summaryrefslogtreecommitdiff
path: root/calc.py
diff options
context:
space:
mode:
authorPanFritz <redstonenoobpan@gmail.com>2015-01-13 13:05:22 +0100
committerPanFritz <redstonenoobpan@gmail.com>2015-01-13 13:05:22 +0100
commit89c5c3e64606276013cfd4c272fbf688a895ed40 (patch)
tree486eddc2d4568e75179bdb4558d40313f7cedc96 /calc.py
parentf85a8e1bab9ae7b1a2ae349a710d21f2a185dcd5 (diff)
Added should_calc check and done expression var
Diffstat (limited to 'calc.py')
-rw-r--r--calc.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/calc.py b/calc.py
index ef2d1a7..d7f030d 100644
--- a/calc.py
+++ b/calc.py
@@ -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