Sum of Prime Factors
Calculate sum of prime factors.
AdvancedPhase 6 - Category 3: Loop & Conditional MixExample 7 of 10
sum-of-prime-factors.py
1# Helper function2def is_prime(n):3 if n < 2:4 return False5 for i in range(2, int(n ** 0.5) + 1):6 if n % i == 0:7 return False8 return True910# Take number11num = int(input("Enter a number: "))1213# Find and sum prime factors14total = 015for i in range(2, num + 1):16 if num % i == 0 and is_prime(i):17 total += i1819print(f"Sum of prime factors: {total}")
Output
Enter a number: 60 Sum of prime factors: 10
What's going on
Find prime factors and sum them.
Key Concepts:
Find prime factors
Sum all prime factors
Return total
🔗Related Content
- 📖
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- 💻
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum