This is a very simple example on how to evaluate a mathematical expression from a string.
Currently only + - * / ^ are possible. I will add more in the future.
If there are any issues, please let me know. I did not have a lot of time for testing.
- "what's 53+7*6/2 ?" -> 74
- "what is 9 * 67+90?" -> 693
- "2^7" -> 128
- "tell me what pi - 23 * (((((-6) + (2 / (65.4 - 114))) + 20) - ((5 * 3) * 2)) - (0.5 / 0.9)) is." -> 384.865871835391
- "-pi+pi" -> 0
- "-pi*2" -> -6.283184
- you can just read the code, if it interests you.
- you can use it as a library by downloading it, importing it in other files, and running the "evaluate" function.
- you can download the file and modify it.
- add this code to the bottom of the file to make it run when you start it:
while True: print(evaluate(input("You: ")))
- add this code to the bottom of the file to make it run when you start it: