Check if a triangle of positive area is possible with the given angles in Python

In geometry, a triangle with positive area must satisfy two conditions: the sum of all angles must equal 180 degrees, and each angle must be positive (greater than 0). Let's explore how to check if three given angles can form a valid triangle.

Problem Understanding

Given three angles, we need to verify if they can form a triangle with positive area. For a valid triangle:

  • All angles must be positive (greater than 0)
  • Sum of all three angles must equal 180 degrees
  • Each angle must be less than 180 degrees (since other two angles must be positive)

Example

Let's implement a function to check triangle validity ?

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

# Test with valid triangle angles
a = 40
b = 120
c = 20
print(f"Angles {a}, {b}, {c}: {solve(a, b, c)}")

# Test with invalid cases
print(f"Angles 0, 90, 90: {solve(0, 90, 90)}")
print(f"Angles 60, 60, 70: {solve(60, 60, 70)}")
Angles 40, 120, 20: True
Angles 0, 90, 90: False
Angles 60, 60, 70: False

Simplified Solution

We can optimize the function since the triangle inequality conditions are automatically satisfied when angles sum to 180 and are all positive ?

def is_valid_triangle(a, b, c):
    # Check if all angles are positive and sum to 180
    return a > 0 and b > 0 and c > 0 and (a + b + c) == 180

# Test cases
test_cases = [
    (40, 120, 20),   # Valid triangle
    (60, 60, 60),    # Equilateral triangle
    (90, 45, 45),    # Right triangle
    (0, 90, 90),     # Invalid: zero angle
    (180, 0, 0),     # Invalid: degenerate case
    (50, 60, 80)     # Invalid: sum ? 180
]

for angles in test_cases:
    a, b, c = angles
    result = is_valid_triangle(a, b, c)
    print(f"Angles {a}°, {b}°, {c}°: {result}")
Angles 40°, 120°, 60°: True
Angles 60°, 60°, 60°: True
Angles 90°, 45°, 45°: True
Angles 0°, 90°, 90°: False
Angles 180°, 0°, 0°: False
Angles 50°, 60°, 80°: False

Mathematical Explanation

The triangle inequality for angles states that each angle must be less than the sum of the other two. However, when three positive angles sum to exactly 180°, this condition is automatically satisfied. This is because if any angle were greater than or equal to the sum of the other two, the total would exceed 180°.

Conclusion

To check if three angles can form a triangle with positive area, simply verify that all angles are positive and their sum equals 180 degrees. The triangle inequality conditions are automatically satisfied when these basic requirements are met.

Updated on: 2026-03-25T14:12:20+05:30

993 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements