### Thread: I need help with basic programming!!(Python)

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
6
Rep Power
0

#### I need help with basic programming!!(Python)

Hey guys! I would really appreciate it if someone helped me! I tried to complete the program but the answer is wrong. Something may be wrong with the calculations but im not sure. Please help!

QUESTION: Given the equations of two lines (y=mx+b)
Determine if the two lines are parallel, the same or intersect.
Calculate and output the point of intersection.

MY CODE:

plus_1 = equation_1.find('+')
plus_2 = equation_2.find('+')

x_1 = equation_1.find('x')
x_2 = equation_2.find('x')

equalsign_1 = equation_1.find('=')
equalsign_2 = equation_2.find('=')

b1 = float(equation_1[x_1+1:])
b2 = float(equation_2[x_2+1:])

m1 = float(equation_1[equalsign_1+1:x_1])
m2 = float(equation_2[equalsign_2+1:x_2])

if m1==m2 and b1!=b2:
print "Your equations are parallel. "

elif m1==m2 and b1==b2:
print "Your equations are the same. "

else:
equation_intersect_y = (b2)-(b1)
equation_intersect_x = (m2)-(m1)
poi_x = (equation_intersect_y)/(equation_intersect_x)
poi_y = (m1)*(poi_x)+(b1)

if m1!=m2 and poi_y>0 and poi_x>0:

elif m1!=m2 and poi_y>0 and poi_x<0:

elif m1!=m2 and poi_y<0 and poi_x<0:

elif m1!=m2 and poi_y<0 and poi_x>0:
2. You need negation.
Code:
`    poi_x = -(equation_intersect_y)/(equation_intersect_x)`
Please use code tags, see my signature.
3. You can reduce the number of comparisons, I think this is simpler logic.
Code:
```equation_1 =raw_input("Please enter the equation of your 1st line(y=mx+b): ")

plus_1 = equation_1.find('+')
plus_2 = equation_2.find('+')

x_1 = equation_1.find('x')
x_2 = equation_2.find('x')

equalsign_1 = equation_1.find('=')
equalsign_2 = equation_2.find('=')

b1 = float(equation_1[x_1+1:])
b2 = float(equation_2[x_2+1:])

m1 = float(equation_1[equalsign_1+1:x_1])
m2 = float(equation_2[equalsign_2+1:x_2])

if m1==m2:
if b1!=b2:
else:
print "Your equations are the same."
else:
equation_intersect_y = (b2)-(b1)
equation_intersect_x = (m2)-(m1)
poi_x = -(equation_intersect_y)/(equation_intersect_x)
poi_y = (m1)*(poi_x)+(b1)
if poi_y>0 and poi_x>0:
elif poi_y>0 and poi_x<0:
elif poi_y<0 and poi_x<0:
elif poi_y<0 and poi_x>0: