943,717 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 1787
  • Python RSS
Jul 13th, 2008
0

Help! Finding a point on a line program

Expand Post »
I get an error when trying to make this program.

python Syntax (Toggle Plain Text)
  1.  
  2. from pointLine import *
  3.  
  4. def calcSlope(x1,y1, x2,y2):
  5. slope = (x2-x1)/(y2-y1)
  6. return slope
  7.  
  8. def calcPointOnLine(y, m, x, b):
  9. if y == (m*x)+ b:
  10. return True
  11. else:
  12. return False
  13.  
  14. print "Point is on a Line? Program"
  15.  
  16. line1 = [(1,7), (7,19)]
  17. x1 = line1[0][0]
  18. x2 = line1[1][0]
  19. y1 = line1[0][1]
  20. y2 = line1[1][1]
  21.  
  22. slope1 = calcSlope(x1,y1,x2,y2)
  23. yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))
  24.  
  25. p1 = Point(3,11)
  26. pointY1 = p1.y
  27. pointX1 = p1.x
  28.  
  29. print "Point(3,11) is on line", line1, ":", \
  30. calcPointOnLine(pointY1, slope1, pointX1, yIntercept)
  31.  
  32. p2 = Point(4,11)
  33. pointX2 = p2.x
  34. pointY2 = p2.y
  35.  
  36. print "Point(4,11) is on line", line1, ":", \
  37. calcPointOnLine (pointY2, slope1, pointX2, yIntercept)

Here's the dreaded error message:

python Syntax (Toggle Plain Text)
  1. Traceback (most recent call last):
  2. File "C:\Users\Me\assignment.py", line 22, in <module>
  3. yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))
  4. TypeError: 'int' object is not callable
Last edited by Mazille; Jul 13th, 2008 at 10:23 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mazille is offline Offline
10 posts
since Jul 2008
Jul 14th, 2008
1

Re: Help! Finding a point on a line program

It appears that you omitted an operator:
yIntercept = y1 - (((y2 - y1)/(x2 - x1))(add operator here)(x1))
Reputation Points: 86
Solved Threads: 40
Junior Poster
solsteel is offline Offline
141 posts
since Mar 2007
Jul 14th, 2008
0

Re: Help! Finding a point on a line program

Click to Expand / Collapse  Quote originally posted by Mazille ...
yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))[/code]
Yes, Python is not a scientific calculator so it does not know that (x-5)(x-4) has an assumed multiplication between parenthesis. You will need to be more specific so change your line to
python Syntax (Toggle Plain Text)
  1. yIntercept = y1 - ( ( ( y2 - y1 ) / ( x2 - x1 ) ) * ( x1 ) )
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008
Jul 16th, 2008
0

Re: Help! Finding a point on a line program

ohhh I forgot about that!!
I actually had copied and pasted that statement.
Thank you very much solsteel and jlm699!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mazille is offline Offline
10 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: If <not number>?
Next Thread in Python Forum Timeline: Directory Picker Control(BOA Constructor)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC