Computer Science, asked by mansishah714, 4 hours ago

Write a python function to check whether three given numbers can form the sides of a triangle.

Answers

Answered by allysia
4

Clearing the Question:

You need to specify what those three numbers are?

Are they coordinated on a cartesian plane?

Or are they measure of sides of the triangle ?

Or they are the interior angles of the triangle?

Since you haven't mentioned I guess I'll have to answer all three scenarios.

Language:

Python

Coordinated on a cartesian plane:

Program:

print("Enter the coordinates in x1,y1,x2,y2,x3,y3 order:")

c=[ int(input(f"value {i+1}: ")) for i in range(0,6)]

det=c[0]*(c[3]-c[5])+c[2]*(c[5]-c[1])+ c[4]*(c[1]-c[3])

if det==0:

   print(f"Traingle not possible through ({c[0]},{c[1]}),({c[2]},{c[3]}),({c[4]},{c[5]}).")

else:

   print(f"Traingle possible through ({c[0]},{c[1]}),({c[2]},{c[3]}),({c[4]},{c[5]}). ")

Logic:

  • Get coordinates
  • Check using 0.5* [x1(y2−y3)+x2(y3−y1)+x3(y1−y2]) if area is 0.
  • If yes triangle not possible if no then it is.

Sides of the triangle :

Program:

a=int(input("Enter side1:" ))

b=int(input("Enter side2:" ))

c=int(input("Enter side3:" ))

if (a+b<=c) or (b+c<=a) or (c+a <=b):

   print(f"Traingle of side lengths {a},{b},{c} not possible. ")

else:

   print(f"Traingle of side lengths {a},{b},{c} possible. ")

Logic:

  • Enter the triangle sides
  • check if sum of any 2 sides is equal to or smaller than third
  • If yes then triangle can't exist

Interior angles of the triangle:

Program:

a=int(input("Enter angle1 (in degrees):" ))

b=int(input("Enter angle2 (in degrees):" ))

c=int(input("Enter angle3 (in degrees):" ))

if a+b+c!=180:

   print(f"Traingle of interior angle {a},{b},{c} not possible. ")

else:

   print(f"Traingle of interior angle  {a},{b},{c} possible. ")

Logic:

  • Enter interior angles
  • check if sum is 180 degrees.

Attachments:

Attachments:
Similar questions