python 3.x - Complete Algebraic Equations -
im trying build app graphs equation based on user input. equation in slope intercept form: y = mx + b
, m
slope , b
y intercept
. however, isn't working me in python!
i tried this:
>>> x = 3 >>> 1/2x
and returned this:
file "<stdin>", line 1 1/2x ^ syntaxerror: invalid syntax >>>
how make returns 1.5?
import re mxb = re.compile('''(?p<slope>[(\d)/.]*)x\s+(?p<sign>[+-])\s+(?p<intercept>[\d./]*)''') s = '1/2x + 5' match = mxb.match(s) if match : print( match.groupdict() )
test python regex here : pythex.org
Comments
Post a Comment