Using Python programming language only. Write a function forms_triangle(a, b, c)
ID: 671748 • Letter: U
Question
Using Python programming language only.
Write a function forms_triangle(a, b, c) that returns True if three segments of length a , b and c can form a triangle, otherwise it returns False. You may assume that your function will be tested with a , b and c that are non-negative integers . You are not allowed to use if (or other branching) statements. Here are the details about when 3 numbers (i.e. 3 side lengths) form a triangle. If you are given three sticks, you may or may not be able to make a triangle with them. For example, if one of the sticks is 10cm long and the other two are 1cm long, you will not be able to form a triangle. For any three non-negative numbers, there is a simple test that determines if it is possible to form a triangle with them. It states: “If any of the three numbers is greater than the sum of the other two, then you cannot form a triangle. Otherwise, you can.” Use this test for your function. In mathematics, this fact is known as the "Triangle Inequality".
Explanation / Answer
def isTriangle(sides):
smallest,medium,biggest = sorted(sides)
return smallest+medium>=biggest
print isTriangle([10,1,1])
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.