Skip to content

Commit 7658ad7

Browse files
committed
Rewrite for more readable code
:):):):):):):):)
1 parent c7dc81f commit 7658ad7

4 files changed

Lines changed: 181 additions & 218 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test.*
2+
__pycache__/

README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,26 @@
77

88
1 result
99

10-
<span style="font-size:0.8em;"> * exageration </span>
10+
<span style="font-size:0.5em;"> * this may or may not be an exageration </span>
11+
12+
Simple parser for math expressions in strings.
1113

1214
## Examples
1315

1416
It can do simple equations
1517
```py
1618
>>> from math_parser import resolve_expr
17-
>>> print(resolve_expr("2^2"))
19+
>>> resolve_expr("2^2") # simple calculations
1820
4
19-
```
20-
21-
Complicated-ish expressions (brackets, order of operations)
22-
```py
23-
>>> from math_parser import resolve_expr
24-
>>> print(resolve_expr("3+(5/7*2-6)"))
21+
>>> resolve_expr("3+(5/7*2-6)") # complicated-ish expressions (brackets & order of operations)
2522
-1.5714285714285712
26-
```
27-
28-
Variable support
29-
```py
30-
>>> from math_parser import resolve_expr
31-
>>> print(resolve_expr("a*12", a=3))
23+
>>> resolve_expr("a*12", a=3) # custom variable support
3224
36
25+
>>> resolve_expr("½ × ⅗") # auto-replaces supported symbols and spaces
26+
0.3
27+
>>> resolve_expr("1+2+3+4+5+6+7*7")
28+
70
29+
>>>
3330
```
3431

35-
One day someone's going to tell me this is [extremely inefficient](https://github.com/QwireDev/MathParser/blob/master/math_parser.py) and they'll probably be right.
32+
[Source?](https://github.com/QwireDev/MathParser/blob/master/math_parser.py)

0 commit comments

Comments
 (0)