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: float, bottom_var: str, espression: str):
out = 0
for char in bottom_var:
pass # somehow parse
for char in expression:
pass # somehow parse
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'
.
EDIT:
To clarify, I mean I want someone to be able to input an assignment under bottom_var
, , and then it being usable within expression
, but nowhere else.
Example:
summation(4, 'x=1', 'x+1')
(would return 14, as 2+3+4+5=14)
question from:https://stackoverflow.com/questions/65650721/how-to-parse-strings-into-variable-function-float-integer-assignment-values