Check Pythagorean Triplet
Take three numbers and check if they can form a Pythagorean triplet.
AdvancedPhase 1 - Level 5: Creative / Tricky Logical ScenariosExample 2 of 10
check-pythagorean-triplet.py
1# Take three numbers2a = int(input("Enter first number: "))3b = int(input("Enter second number: "))4c = int(input("Enter third number: "))56# Check all possible arrangements7if (a*a + b*b == c*c) or (b*b + c*c == a*a) or (c*c + a*a == b*b):8 print("Pythagorean triplet")9else:10 print("Not a Pythagorean triplet")
Output
Enter first number: 3 Enter second number: 4 Enter third number: 5 Pythagorean triplet Enter first number: 2 Enter second number: 3 Enter third number: 4 Not a Pythagorean triplet
What's going on
Check all three possible arrangements since we don't know which is hypotenuse.
Key Concepts:
Pythagorean theorem: a² + b² = c²
Check all arrangements: a²+b²=c², b²+c²=a², c²+a²=b²
Use OR to check if any arrangement works
🔗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