I want to write a summation function, but can't figure out how I would parse the bottom expression and right expression.
def summation(count: int, bottom_var: str, espression: str):
out = 0
# parse bottom_var into a variable and it's value
value = ···
var_name = ···
expression.replace(var_name, value)
···
I want you to be able to use the inputs the same way as in normal sigma notation, as in bottom_var
is 'n=13'
, not '13'
.
You enter an assignment for bottom_var
, and an expression using the variable defined in bottom_var
in expression
.
Example:
summation(4, 'x=1', 'x+1')
(would return 14, as 2+3+4+5=14)