Suppose we have three angles. We have to check whether it is possible to create a triangle of positive area with these angles or not.
So, if the input is like a = 40 b = 120 c = 20, then the output will be True as the sum of 40 + 120 + 20 = 180.
To solve this, we will follow these steps −
- if a, b and c are not 0 and (a + b + c) is same as 180, then
- if (a + b) >= c or (b + c) >= a or (a + c) >= b, then
- return True
- otherwise,
- return False
- if (a + b) >= c or (b + c) >= a or (a + c) >= b, then
- otherwise,
- return False
Let us see the following implementation to get better understanding −
Example
def solve(a, b, c): if a != 0 and b != 0 and c != 0 and (a + b + c) == 180: if (a + b)>= c or (b + c)>= a or (a + c)>= b: return True else: return False else: return False a = 40 b = 120 c = 20 print(solve(a, b, c))
Input
40, 120, 20
Output
True