Strong Number Check
Check if a number is strong number.
IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 8 of 13
strong-number-check.py
1# Take number2num = int(input("Enter a number: "))34# Calculate factorial function5def fact(n):6 if n == 0 or n == 1:7 return 18 result = 19 for i in range(2, n + 1):10 result *= i11 return result1213# Check strong number14temp = num15strong_sum = 016while temp > 0:17 digit = temp % 1018 strong_sum += fact(digit)19 temp //= 102021if strong_sum == num:22 print("Strong number")23else:24 print("Not a strong number")
Output
Enter a number: 145 Strong number Enter a number: 123 Not a strong number
What's going on
Strong number: sum of factorial of digits equals the number.
Key Concepts:
Extract each digit
Calculate factorial of digit
Sum all factorials
Compare with original
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum