https://github.com/subatomicplanets/simplestringmath
A very simple python script which can do math on user-written strings
https://github.com/subatomicplanets/simplestringmath
algorithms data-structures lightweight math numbers python python3 real-time shunting-yard-algorithm simple string-algorithms string-manipulation strings
Last synced: 6 months ago
JSON representation
A very simple python script which can do math on user-written strings
- Host: GitHub
- URL: https://github.com/subatomicplanets/simplestringmath
- Owner: SubatomicPlanets
- License: mit
- Created: 2023-06-19T13:40:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-20T19:56:09.000Z (over 1 year ago)
- Last Synced: 2024-06-21T14:00:04.204Z (over 1 year ago)
- Topics: algorithms, data-structures, lightweight, math, numbers, python, python3, real-time, shunting-yard-algorithm, simple, string-algorithms, string-manipulation, strings
- Language: Python
- Homepage:
- Size: 27.3 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleStringMath
This is a very simple example on how to evaluate a mathematical expression from a string.
It is only one file, simple to use, and is only 100 lines long.
It can evaluate written out words, and calculate math expressions.
I made this in python 3.8.10, but really any version should work. I am using only one library, which is built in.
Currently only + - * / ^ % are possible.
If there are any issues, please let me know. I did not have a lot of time for testing.# Examples:
- "what's fifty three+7*6/2?" -> 74
- "what is 9 * 67+90?" -> 693
- "2^7" -> 128
- "tell me what pi - 23 * (((((-6) + (2 / (65.4 - one hundred and fourteen))) + 20) - ((5 * 3) * two)) - (0.5 / 0.9)) is." -> 384.865871835391
- "-pi+pi" -> 0
- "-pi*two" -> -6.283184
- "(twenty two*2)+one" -> 45# How to use
1. you can just read the code, if it interests you.
2. you can use it as a library by downloading it, importing it in other files, and running the "evaluate" function.
3. 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: ")))
```