def divide(a, b):

return a/b

def pow(a, b):

return a**b

def addA(a, b):

return a+b

def subA(a, b):

return a-b

def mul (a, b):

return a*b

operators = {

'+': addA,

'-': subA,

'*': mul,

'/': divide,

'^' : pow,

}

def calculate(s):

if s.isdigit():

return float(s)

elif '[' in s:

start = s.index('[')

end = s.rindex(']')

return calculate(s[start + 1:end])

for c in operators.keys():

left, operator, right = s.partition(c)

if operator in operators:

return operators[operator](calculate(left), calculate(right))

calc = input("Type calculation:\n")

print("Answer: " + str(calculate(calc)))

input: [2+2]+[2+2] output: None

input [2+3]*2 output 5