Check if Three Sides Form a Valid Triangle
Take three sides and check if they form a valid triangle.
IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 1 of 10
check-if-three-sides-form-a-valid-triangle.py
1# Take three sides as input2a = float(input("Enter side 1: "))3b = float(input("Enter side 2: "))4c = float(input("Enter side 3: "))56# Check if valid triangle7if a + b > c and b + c > a and c + a > b:8 print("Valid triangle")9else:10 print("Invalid triangle")
Output
Enter side 1: 3 Enter side 2: 4 Enter side 3: 5 Valid triangle Enter side 1: 1 Enter side 2: 2 Enter side 3: 5 Invalid triangle
What's going on
Triangle inequality theorem: Sum of any two sides must be greater than the third side.
Key Concepts:
Check all three combinations: a+b>c, b+c>a, c+a>b
Use
and to ensure all conditions are metAll three conditions must be True for a valid triangle
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum