Sum of All Factors
Calculate sum of all factors of a number.
IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 7 of 13
sum-of-all-factors.py
1# Take number2num = int(input("Enter a number: "))34# Sum factors5factor_sum = 06for i in range(1, num + 1):7 if num % i == 0:8 factor_sum += i910print(f"Sum of factors: {factor_sum}")
Output
Enter a number: 12 Sum of factors: 28
What's going on
Find all factors and sum them.
Key Concepts:
Find all factors
Add each factor to sum
Print total sum
🔗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