Skip to content

Created sum_of_harmonic_series.py #7504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 23, 2022
38 changes: 38 additions & 0 deletions maths/sum_of_harmonic_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def sum_of_harmonic_progression(
first_term: float, common_difference: float, no_of_terms: int
) -> float:

"""

Find the sum of n terms in an harmonic progression.
common_diff is the common difference of Arithmetic
Progression by which the given Harmonic Progression is linked.


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are doctests.

"""

arithmetic_progression = [1 / first_term]
i = 0
first_term = 1 / first_term
while i < no_of_terms - 1:
first_term = first_term + common_difference
l1.append(first_term)

"""
l1 is the Arithmetic Progression linked to the given Harmonic Series
l2 is the given Harmonic Series

"""

i += 1
harmonic_series = [1 / step for step in arithmetic_progression]
return sum(l2)




if __name__ == "__main__":
import doctest
doctest.testmod()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is the doctest


print(sum_of_hp(1 / 2, 2, 2))