Last active
February 14, 2020 06:40
-
-
Save nagavenkateshgowru/e083744a0f01fc1cfd385daea1ae780d to your computer and use it in GitHub Desktop.
Added get_values_from_expr method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_values_from_expr(expression): | |
if "+" in expression: | |
raw_values = expression.split("+") | |
print(raw_values) | |
# raw_values is a list of operands like ['120 ',' 20'] with extra spaces | |
values = list(map(str.strip, raw_values)) | |
else: | |
raw_values = expression.split("-") | |
print(raw_values) | |
# raw_values is a list of operands like ['120 ',' 20'] with extra spaces | |
values = list(map(str.strip, raw_values)) | |
return values | |
def calc(expression): | |
if '+' in expression: | |
value1 = expression.split('+')[0] | |
value2 = expression.split('+')[1] | |
result = int(value1) + int(value2) | |
else: | |
value1 = expression.split('-')[0] | |
value2 = expression.split('-')[1] | |
result = int(value1) - int(value2) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment