Sum of Harmonic Series
Calculate sum of harmonic series.
IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 12 of 13
sum-of-harmonic-series.py
1# Take n2n = int(input("Enter n: "))34# Calculate sum5harmonic_sum = 06for i in range(1, n + 1):7 harmonic_sum += 1 / i89print(f"Sum: {harmonic_sum:.4f}")
Output
Enter n: 5 Sum: 2.2833
What's going on
Add reciprocals to get harmonic sum.
Key Concepts:
Sum 1/i for i from 1 to n
Accumulate in loop
Format decimal output
🔗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