# Program to determine if 3 points lie on a line # (user enters points) # Matt Bishop, May 1, 2009 # for ECS 10 Spring 2009 # this routine determines if 3 points are on a line # parameters: x1, y1: x, y co-ordinates of first point # x2, y2: x, y co-ordinates of second point # x3, y3: x, y co-ordinates of third point # side effect: prints message giving answer def isline(x1, y1, x2, y2, x3, y3): # check for everything being on horizontal line if (x1 == x2): if (x2 == x3): print "The points are on the same horizontal line"; else: print "The points are not on the same line"; else: # now compute the slope and y-intercept for 2 points m = (float(y2)-float(y1))/(float(x2)-float(x1)); b = y2 - m * x2 # now see if (x3, y3) are on the same line if (y3 == m * x3 + b): print "The points are on the same (non-horizontal) line"; else: print "The points are not on the same line"; # this routine generates a prompt to ask for a point # parameters: what: which point (first, second, third) do you want? # returns: the prompt as a string def prompt(what): # generate the prompt and return it s = "Enter the " + what + " point's co-ordinates separated by a comma: "; return s; # now put it all together # calls: prompt: generates user prompt # isline: to determine if points lie on same line def main(): x1, y1 = input(prompt("first")); x2, y2 = input(prompt("second")); x3, y3 = input(prompt("third")); isline(x1, y1, x2, y2, x3, y3); main()