-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Changes from 5 commits
bbe97da
4154aea
69a9c24
4ef0e17
82dedcb
e9cb590
eb63149
ae928a5
2dfcc1e
24b2005
1cea14e
634f320
646e166
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
""" | ||
|
||
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. | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add doctests here: https://docs.python.org/3/library/doctest.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are doctests. |
||
""" | ||
|
||
l1 = [1 / first_term] | ||
AkshitGulyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
i = 0 | ||
first_term = 1 / first_term | ||
while i < no_of_terms - 1: | ||
first_term = first_term + common_difference | ||
AkshitGulyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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] | ||
AkshitGulyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return sum(l2) | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
doctest.testmod() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is the doctest |
||
|
||
print(sum_of_hp(1 / 2, 2, 2)) |
There was a problem hiding this comment.
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 functionsum_of_harmonic_progression