Input the math expression such as 3+2*{1+2*[-4/(8-6)+7]} make the python program calculate. The problem is, it gives no output. How to fix this problem.
while True:
try:
express = input()
express.replace("[", "(")
express.replace("{", "(")
express.replace("]", ")")
express.replace("}", ")")
print(eval(express))
except:
break
1 Answer 1
Update: After each replacement, we must update the expression, otherwise the change will only reflect to the given expression & after each replace statement it will change and only modify the given expression
while True:
try:
express = input()
x = express.replace("[", "(")
y = x.replace("{", "(")
z = y.replace("]", ")")
w = z.replace("}", ")")
print(eval(w))
except:
break
Sign up to request clarification or add additional context in comments.
lang-py