In: Computer Science
1.1
Write a python in Jupiter notebook function called
trng that takes three numbers x, y, and z, and
specifies if those can form a triangle (i.e., returns the word
triangle if they can, and Not a triangle otherwise).
Note: In order for three numbers to form a triangle sum of
any two of them must be greater than the third one
(e.g., x=1, y=2, z=4 cannot form a triangle because x+y is not
greater than z even though x+z>y and y+z>x).
2.2 Write a program that gets three numbers from user and by calling the trng function you defined above specify if those numbers could be three sides of a triangle.
Example:
Enter the first number: 3.2
Enter the second number: 4
Enter the third number: 7.5
Not a triangle
Python code:
#1.1)
#trng function
def trng(x,y,z):
#checking if the sum of any 2 side is greater
than the 3rd side
if(x+y>z and y+z>x and x+z>y):
#trianle is
returned
return("triangle")
else:
#Not a trianle is
returned
return("Not a
triangle")
#2.2)
#accepting x
x=float(input("Enter the first number: "))
#accepting y
y=float(input("Enter the second number: "))
#accepting z
z=float(input("Enter the third number: "))
#printing returned of trng function for x,y,z as input
print(trng(x,y,z))
Screenshot:
Input and Output: