Write a program that takes as input two opposite corners of a rectangle: (x1,y1) and (x2,y2). Finally, the user is prompted for the coordinates of a third point (x,y). The program should print Boolean value True or False based on whether the point (x,y) lies inside the rectangle. If the point lies on the rectangle, the program should print False.

Respuesta :

Answer:

A python3 script is given below

Explanation:

Hi there!

In this program it is assumed that the rectangle will always be parallel to the x and y axis

# First we define three lists where the coordinates will be stored

# The notrect variable will help us if the p1 and p2 coordinates are along the same axis and therefore the will not make a rectangle,in the assumed sense

p1, p2, p3 = [],[],[]

notrect = False

# In this for cycle we ask the user for the coordinates and check if the first two make a rectangle

for i in range(3):

if i<2:

 x = float(input('Please write x'+str(i+1)+': '))

 y = float(input('Please write y'+str(i+1)+': '))

else:

               x = float(input('Please write x: '))

               y = float(input('Please write y: '))

if i==0: p1 = [x,y]

elif i==1: p2 = [x,y]

else: p3 = [x,y]

# If they do not make the rectangle we no longer ask for the third and exit the program

if p1 and p2:

 if p1[0] == p2[0] or p1[1] == p2[1]:

  notrect = True

  print('These ponits does not make a rectangle')

  break

#If notrect = True we say Bye to the user and nothing else happens

if notrect:

print('Bye')

# If they do make the rectangle we save the x and y coordinates of the rectangle separately, and sort them

else:

x = [p1[0],p2[0]]

y = [p1[1],p2[1]]

x.sort()

y.sort()

# If the x and y coordinates of the third point are between the x and y coordinates of the vertices of the rectangle the last point is indeed inside the rectangle, and print a True. Otherwise, we print a False

print((p3[0]>x[0] and p3[0]<x[1]) and p3[1]>y[0] and p3[1]<y[1])

The required codes are attached below:

Boolean value:

In programming, we generally need to implement values that can only have one of two values, either true or false. For this purpose, Java provides a special data type, i.e., boolean, which can take the values true or false.

Learn More information about the topic Boolean value:

https://brainly.com/question/26413022

Ver imagen Omm2
Ver imagen Omm2
Ver imagen Omm2