Determine Triangle Type
If sides form a valid triangle, determine if it is equilateral, isosceles, or scalene.
IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 2 of 10
determine-triangle-type.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 # Valid triangle - determine type9 if a == b == c:10 print("Equilateral")11 elif a == b or b == c or c == a:12 print("Isosceles")13 else:14 print("Scalene")15else:16 print("Invalid triangle")
Output
Enter side 1: 5 Enter side 2: 5 Enter side 3: 5 Equilateral Enter side 1: 5 Enter side 2: 5 Enter side 3: 6 Isosceles
What's going on
After validating triangle, check side equality.
Key Concepts:
Equilateral: all sides equal (a == b == c)
Isosceles: two sides equal (a==b or b==c or c==a)
Scalene: all sides different
Use nested if-elif-else structure
🔗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