Tutorialspoint
Problem
Solution
Submissions

Check if a Triangle is Valid Given Its Three Angles

Certification: Basic Level Accuracy: 41.67% Submissions: 84 Points: 5

Write a Python program that determines whether three given angles can form a valid triangle.

Example 1
  • Input: angles = [60, 60, 60]
  • Output: True
  • Explanation:
    • Step 1: Check if all angles are greater than 0. Yes, all are 60 > 0.
    • Step 2: Check if the sum of angles equals 180. 60 + 60 + 60 = 180. Yes.
    • Step 3: Since both conditions are met, return True.
Example 2
  • Input: angles = [90, 30, 0]
  • Output: False
  • Explanation:
    • Step 1: Check if all angles are greater than 0. No, one angle is 0.
    • Step 2: Even though the sum 90 + 30 + 0 = 120 (≠ 180), we return False because one angle is 0.
Constraints
  • 0 ≤ angle ≤ 180
  • Time Complexity: O(1)
  • Space Complexity: O(1)
NumberFunctions / MethodsFacebookGoldman Sachs
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Check if all angles are greater than 0
  • Verify the sum of angles equals exactly 180 degrees

Steps to solve by this approach:

 Step 1: Check if all three angles are positive values.

 Step 2: Verify that all angles are greater than 0 degrees.
 Step 3: Calculate the sum of all three angles.
 Step 4: Check if the sum equals exactly 180 degrees (triangle angle sum property).
 Step 5: Return True if both conditions are met, False otherwise.

Submitted Code :