CoursesCSS StudioExamplesGATECompaniesPrepMentora
Programs/Logic building/Phase 6 - Category 4: Mathematical Combinations

4 / 10

Next
1. Sum of Squares2. Sum of Cubes3. Alternating Sum4. Harmonic Series Sum5. Geometric Series Sum6. Print Nth Row of Pascal Triangle7. Catalan Numbers8. Tribonacci Series9. Lucas Series10. Pell Series

Phase 6 - Category 4: Mathematical Combinations

  1. 01Sum of Squares
  2. 02Sum of Cubes
  3. 03Alternating Sum
  4. 04Harmonic Series Sum
  5. 05Geometric Series Sum
  6. 06Print Nth Row of Pascal Triangle
  7. 07Catalan Numbers
  8. 08Tribonacci Series
  9. 09Lucas Series
  10. 10Pell Series

Harmonic Series Sum

Calculate 1 + 1/2 + 1/3 + ... + 1/n.

IntermediatePhase 6 - Category 4: Mathematical CombinationsExample 4 of 10
harmonic-series-sum.py
1# Take n
2n = int(input("Enter n: "))
3
4# Calculate harmonic sum
5total = 0.0
6for i in range(1, n + 1):
7 total += 1.0 / i
8
9print(f"Harmonic sum: {total}")

Output

Enter n: 5
Harmonic sum: 2.283333333333333

What's going on

Sum reciprocals of numbers.

Key Concepts:

Loop from 1 to n
Add 1/i to sum
Use float division

🔗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

PreviousAlternating SumNextGeometric Series Sum

On this page

CodeOutputExplanation
Up nextGeometric Series Sum
Schoolabe

Learn, Practice, Ace Coding

ExamplesCompaniesTutorialsCSS StudioDSA VisualizersQuizInterview PrepMentoraCareer QuestGATE CS prepGATE CS 2027 study planJob ReadyInternships
AboutContactCareersAffiliate programBlog
DocumentationAPI ReferenceCommunitySupport
Privacy PolicyTermsRefund PolicyCookie Policy

© 2026 Schoolabe