Skip to content

Instantly share code, notes, and snippets.

@nagavenkateshgowru
Last active February 14, 2020 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagavenkateshgowru/e083744a0f01fc1cfd385daea1ae780d to your computer and use it in GitHub Desktop.
Save nagavenkateshgowru/e083744a0f01fc1cfd385daea1ae780d to your computer and use it in GitHub Desktop.
Added get_values_from_expr method
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