Write a program to ask for a Cartesian coordinate x,y. Your program should read in an x value and a y value and then inform the user whether it is the origin (0,0), on the y axis, eg (0, 10), on the x axis, eg (-3,0) or in which quadrant it appears.

Respuesta :

Answer:

The program in Python is as follows:

x = int(input("x: "))

y = int(input("y: "))

if x == 0:

   if y == 0:        print("Origin")

   else:        print("y axis")

elif x>0:

   if y > 0:        print("First Quadrant")

   elif y < 0:        print("Fourth Quadrant")

   else:        print("x axis")

elif x < 0:

   if y > 0:        print("Second Quadrant")

   elif y < 0:        print("Third Quadrant")

   else:        print("x axis")

Explanation:

These get input for x and y

x = int(input("x: "))

y = int(input("y: "))

If x is 0

if x == 0:

............ and y is 0, then the point is at origin

   if y == 0:        print("Origin")

............ and y is not 0, then the point is on y-axis

   else:        print("y axis")

If x is greater than 0

elif x>0:

............ and y is greater than 0, then the point is at in the first quadrant

   if y > 0:        print("First Quadrant")

............ and y is less than 0, then the point is at in the fourth quadrant

   elif y < 0:        print("Fourth Quadrant")

............ Otherwise, the point is on the x axis

   else:        print("x axis")

If x is less than 0

elif x < 0:

............ and y is greater than 0, then the point is at in the second quadrant

   if y > 0:        print("Second Quadrant")

............ and y is less than 0, then the point is at in the third quadrant

   elif y < 0:        print("Third Quadrant")

............ Otherwise, the point is on the x axis

   else:        print("x axis")