Question: Language: Python Specification - Given the attached code, import the module and use the functions to ask the user for two equations of a lines.

Language: Python

Specification - Given the attached code, import the module and use the functions to ask the user for two equations of a lines. Use the module function to decipher the functions and output the intersection point. Currenty only allow basic operations (no parenthesis)...but could support more options in the future. Sample Output:

The attached code:

def solveEq(x1, b1, x2, b2): x = (b2-b1)/(x1-x2) y = x1*x+b1 return (x,y)

def parseEq(eq): sides = eq.split("=") if len(sides)==1: print("Not valid, must have an equal sign") return None if len(sides)>2: print("Too many equal signs") coef = parseSide(sides[0].lower()) coef2 = parseSide(sides[1].lower()) if coef is None: return None if coef2 is None: return None y = coef[1]-coef2[1] x = coef[0]-coef2[0] n = coef[2]-coef2[2] if y==0: print("Currently only supporting equations that have y") return None x/=y n/=y return (x,n)

def parseSide(eq): noSpace = "" allowedChars = 'xy*-+/' for l in eq: if l.isnumeric() or l in allowedChars: noSpace+=l elif l=='.': print("Floating point numbers not allowed atm") return None elif l!=' ' and l!='\t': print("Not valid, no special characters ({})".format(l)) return None adds = noSpace.split("+") simParts = [] coef = [] for add in adds: ss = add.split("-") simParts+=ss coef+=[1]+[-1]*(len(ss)-1) x=0 y=0 n=0 for i,c in enumerate(coef): p = parseSimple(simParts[i]) if p is None: return None if 'x' in p: x+=c*p['x'] if 'y' in p: y+=c*p['y'] if 'num' in p: n+=c*p['num'] return (x,y,n) def parseSimple(part): mult = part.split("*") ps = [] types = [] for m in mult: pss = m.split("/") ps+=pss types+=[1]+[-1]*(len(pss)-1) val = None key = 'num' for i,p in enumerate(ps): if p.isnumeric(): if val is None: val=1 if types[i]==1: val*=int(p) else: val/=int(p) if p=='x': if key!='num': print("Non-linear equation") return None key='x' if p=='y': if key!='num': print("Non-linear equation") return None key='y' return {key:val}

if __name__=='__main__': print(parseSimple("2*x*3")) print(parseSimple("2*x*3*y")) print(parseSimple("2*y/3")) print(parseSimple("12/3")) print(parseSide("2*x+3")) print(parseEq("3*y = 2*x+3"))

Language: Python Specification - Given the attached code, import the module and

Sample Output: Enter Equation 1: x+3 Not valid, must have equal sign Enter Equation 1: y = x+3 Enter Equation 2: y/3 = 100x+(3-10) Not valid, special characters (0) Enter Equation 2: y/3 = -10z+(3-10) Only x and y allowed Enter Equation 2: y = -x Intercept at (-.6666,0) Sample Output: Enter Equation 1: x+3 Not valid, must have equal sign Enter Equation 1: y = x+3 Enter Equation 2: y/3 = 100x+(3-10) Not valid, special characters (0) Enter Equation 2: y/3 = -10z+(3-10) Only x and y allowed Enter Equation 2: y = -x Intercept at (-.6666,0)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!