I am creating a simple Python calculator that uses the order of operations to do simple math, and adds in a square root and integer division feature. The concept is that the user could enclose the value they want to be square rooted within a sqr()
function (for example, sqr(25)
is equal to 5).
The problem is, I am having trouble pulling this value out of the equation string. Here is a pseudo-code of what it should do:
b = 'sqr(25)+5*3' # equation
# My pseudo-code:
# 1. Identify use of sqr()
# 2. Pull 'sqr(25)' out to be solved
# 3. Pull value (25) out and solve it with math.sqrt()
# 4. Replace 'sqr(25)' with the solved value (5)
#
# b should now be equal to:
# '5+5*3'
I am having trouble with pulling out the value from sqr()
and putting it back in the correct spot. I tried looking online but this seems to be a bit more of an obscure question.