-2

Im trying to build an app that graphs an equation based on user input. The equation would be in slope intercept form: y = mx + b, for m as slope and b as y intercept. However, this isn't working for me in python!

I tried this:

>>> x = 3
>>> 1/2x

and was returned this:

  File "<stdin>", line 1
    1/2x
       ^
SyntaxError: invalid syntax
>>>

How would I make it so that this returns 1.5?

doejs
  • 96
  • 10

1 Answers1

0
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 the python regex here : pythex.org

corn3lius
  • 4,857
  • 2
  • 31
  • 36
  • The goal is to solve it as is. The user needs to be able to enter the equation of the line. – doejs Sep 07 '16 at 15:06