#!/usr/bin/env python # # a simple program computing distances # # written by e.bonakdarian dec 2010 # from math import sqrt def distance(x, y, other_x, other_y): # compute the distance between this point # and the other point on the plane x_diff = other_x - x y_diff = other_y - y dist = sqrt((x_diff**2) + (y_diff**2)) return dist def main(): tom_start_x = 200 tom_start_y = 300 tom_end_x = 500 tom_end_y = 700 mary_start_x = 234 mary_start_y = -300 mary_end_x = 200 mary_end_y = 0 tom_distance = distance(tom_start_x, tom_start_y, tom_end_x, tom_end_y) mary_distance = distance(mary_start_x, mary_start_y, mary_end_x, mary_end_y) print 'Tom traveled %.2f units.' % tom_distance print 'Mary traveled %.2f units.' % mary_distance if tom_distance > mary_distance: print 'Tom traveled further.' elif mary_distance > tom_distance: print 'Mary traveled further.' else: print 'Both traveled the same distance.' if __name__ == '__main__': main()