I am writing a command line calculator. I have all the math down but I want to add my own functions, like solve("x^3 = 8", x). My math works fine but the way I'm using exec() is preventing it from writing the result to the local variable finalAnswer.

I included foo() to show what I want

```
def foo():
    return 5
exec("a = foo()")
print(a)

result = "addAB(15,8)"

def addAB(A, B):
    print(A+B)
    return A+B

def __runFunc(fn, param):
    exec("finalAnswer = fn(" + param + ")")

__approvedFunctions = set(["addAB", "subtractAB"])

funcName = result[:result.index('(')]
if(funcName in __approvedFunctions):
    param = result[result.index('(')+1 : result.index(')')]
    if callable(globals()[funcName]):
        __runFunc(globals()[funcName], param)
print(finalAnswer)

```

On execution my output is:

```
addAB(15,8)
5
23
Traceback (most recent call last):
  File "C:/Users/mikeo/OneDrive/Documents/function filter.py", line 45, in 
<module>
    print(finalAnswer)
NameError: name 'finalAnswer' is not defined

```

The first three lines of the output tell me that every part of the script executes, but finalAnswer isn't getting initialized. Have I missed some nuance of using exec().

Also, bonus points if you help me remove exec without changing the format of the string input calling a parameterized function and storing the returned value locally.