# Test module to see if a point is within the unit circle # Points are assumed to be in rectangle (-1, -1) and (+1, +1) # (i.e., ***no*** error checking!) # # Matt Bishop, MHI 289I, Fall 2024 # # for point x, y, if x^2 + y^2 <= 1, they are in the unit circle # parameters: x, y: co-ordinates of point # returns True if so, False if not def inunitcircle(x, y): return x ** 2 + y ** 2 <= 1 # main routine to enable us to test gettoss() def main(): # get co-ordinates try: x = float(input("[Number only; < -1 or > 1 quits] x co-ordinate: ")) y = float(input("[Number only; < -1 or > 1 quits] y co-ordinate: ")) except: print("Bye!") return # generate that many in the obvious way while -1 <= x and x <= 1: # print each one out print("(%f,%f) is" % (x, y),end=' ') # announce result if inunitcircle(x, y): print("in", end=' ') else: print("not in", end=' ') print("the unit circle") # get co-ordinates try: x = float(input("[Number only; < -1 or > 1 quits] x co-ordinate: ")) y = float(input("[Number only; < -1 or > 1 quits] y co-ordinate: ")) except: print("Bye!") return main()