Created
February 14, 2020 06:52
Star
You must be signed in to star a gist
Consuming get_values_from_expr
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: | |
values = get_values_from_expr(expression) | |
result = int(values[0]) + int(values[1]) | |
else: | |
values = get_values_from_expr(expression) | |
result = int(values[0]) - int(values[1]) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment