Skip to content

Instantly share code, notes, and snippets.

@nagavenkateshgowru
Created February 14, 2020 06:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nagavenkateshgowru/624c234200c27ef4c3d25a37d78aeeac to your computer and use it in GitHub Desktop.
Consuming get_values_from_expr
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