Print Harmonic Series
Print harmonic series: 1 + 1/2 + 1/3 + ... + 1/n.
IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 11 of 13
print-harmonic-series.py
1# Take n2n = int(input("Enter n: "))34# Print harmonic series5print("Harmonic series:")6for i in range(1, n + 1):7 print(f"1/{i}", end="")8 if i < n:9 print(" + ", end="")10print()
Output
Enter n: 5 Harmonic series: 1/1 + 1/2 + 1/3 + 1/4 + 1/5
What's going on
Print fractions in harmonic series format.
Key Concepts:
Loop from 1 to n
Print 1/i for each term
Add + between terms
🔗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