Answer:
tryagain = "Y"
while tryagain.upper() == "Y":
x1 = int(input("x1: "))
y1 = int(input("y1: "))
x2 = int(input("x2: "))
y2 = int(input("y2: "))
x3 = int(input("x3: "))
y3 = int(input("y3: "))
area = abs(x1 *(y2 - y3) + x2 * (y1 - y3) + x3 * (y1 - y2))
if area > 0:
print("Inputs form a triangle")
else:
print("Inputs do not form a triangle")
tryagain = input("Press Y/y to try again: ")
Explanation:
To check for this, we will simply compute the area of the triangle given that inputs are on a coordinate plane i.e. (x,y).
An area greater than 0 means it's a triangle
Conversely, if not, it's not a triangle.
This line starts the loop with variable tryagain set to Y
tryagain = "Y"
while tryagain.upper() == "Y":
Following lines retrieve the triangle's coordinates x1 = int(input("x1: "))
y1 = int(input("y1: "))
x2 = int(input("x2: "))
y2 = int(input("y2: "))
x3 = int(input("x3: "))
y3 = int(input("y3: "))
Now, this computes the area
area = abs(x1 *(y2 - y3) + x2 * (y1 - y3) + x3 * (y1 - y2))
Finally, this checks the condition mentioned above.
if area > 0:
print("Inputs form a triangle") This message appears if the condition is true
else:
print("Inputs do not form a triangle") This is printed if the condition is not met
tryagain = input("Press Y/y to try again: ") It prompts the user to input new values