Computer Science, asked by vidya1619, 1 year ago

python program to check whether three given numbers can form the sides of a triangle​

Answers

Answered by codiepienagoya
1

Program to check sides of a triangle​

Output:

Input first side of the triangle: 5

Input second side of the triangle: 3

Input third side of the triangle: 4

Input number forms a triangle

Explanation:

The python program to find the given input form a triangle as follows:

Program:

a=int(input('Input first side of the triangle: ')) #defining variable a and taking input by user

b=int(input('Input second side of the triangle: ')) #defining variable b and taking input by user

c=int(input('Input third side of the triangle: ')) #defining variable c and taking input by user

if (a+b)>c:  #checking condition

   if (b+c)>a:  #checking inner condition

       if (a+c)>b: #checking inner condition

           print("Input number forms a triangle") #print message

       else: #else part when condition false

           print("Input number does not form a triangle") #print message

Explanation of the program:

  • In the above code three variable "a, b, and c" is declared that uses input function and int, in which input function is used for taking input from the user and int is used to convert input into digit.
  • In the next line, if the conditional statement is used that checks that input number form a triangle or not, in this condition two inners if block is used that uses Pythagorean theorem. if the condition is true it will print "Input number forms a triangle".
  • If the given input does not fulfill the condition it will print "Input number does not form a triangle".

Learn more:

  • what is triangle: https://brainly.in/question/7747016  
  • Program: https://brainly.in/question/5558161
Answered by Equestriadash
5

The following codes must be typed in script mode, saved and then executed.

Here, we'll be using the IF - ELSE function. It is a function that decides the result based on a given condition.

It will run the body of the code, only if the condition is true. Otherwise, the 'else' code of the value inputted will be executed.

CODE:

x = float(input("Enter the length of the first side:"))

y = float(input("Enter the length of the second side:"))

z = float(input("Enter the length of the third side:"))

if (x + y)> z:

   print("A triangle can be formed with the given sides.")

else:

   print("A triangle cannot be formed with the given sides:")

OUTPUT:

Attachments:
Similar questions