# Precision of the checks for the next exercise epsilon = 0.0001 """ Solve the third problem. """ print "\n\n# Problem #3 : take a point O and a radius r, and take a second point A, then check if it is inside, on or outside the circle C(O, r)." # Input point P print "\nFor the first point O:" o_x = 0 o_y = 0 # Input radius r print "\nFor the radius r:" r = 4 assert r >= 0 # Input point A print "\nFor the second point A:" a_x = 2 a_y = -3 # This is durty, usually we import modules in the beginning of the program from math import sqrt # And now check if the point is on the circle or not distance = sqrt((a_x - o_x)**2 + (a_y - o_y)**2) if distance < r - epsilon: print "The point A is inside the circle C(O, r) !" elif r - epsilon <= distance <= r + epsilon: print "The point A is on the circle C(O, r) !" elif r + epsilon < distance: print "The point A is outside the circle C(O, r) !" else: print "Some weird thing is here!" print "Done"