DEV Community

KwarDee
KwarDee

Posted on

A string to calculation in python

I'm trying to write a program that takes a string like these,"5+5" or "5+5(5×5)" and convert into something calculateable.
It seemed so easy but I've been struggling to come up with solutions.

Top comments (2)

Collapse
 
spez profile image
Abhigyan • Edited

There is a built-in function available in Python 3.x. The "eval()" function requires a string to be passed on and returns the calculated value for it. It's even available in JavaScript, BTW...

Read more here

Collapse
 
kwardee profile image
KwarDee

Thank you so so much 💯