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
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions maths/sum_of_harmonic_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def sum_of_harmonic_progression(first_term: float, common_difference: float, no_of_terms: int) -> float:

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file maths/sum_of_harmonic_series.py, please provide doctest for the function sum_of_harmonic_progression

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file maths/sum_of_harmonic_series.py, please provide doctest for the function sum_of_harmonic_progression

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file maths/sum_of_harmonic_series.py, please provide doctest for the function sum_of_harmonic_progression


"""

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.

"""

l1 = [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
l2 = [1 / x for x in l1]
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))