-
-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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 8 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,38 @@ | ||
def sum_of_harmonic_progression( | ||
AkshitGulyan marked this conversation as resolved.
Show resolved
Hide resolved
AkshitGulyan marked this conversation as resolved.
Show resolved
Hide resolved
AkshitGulyan marked this conversation as resolved.
Show resolved
Hide resolved
AkshitGulyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. | ||
|
||
|
||
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. |
||
""" | ||
|
||
arithmetic_progression = [1 / first_term] | ||
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 | ||
harmonic_series = [1 / step for step in arithmetic_progression] | ||
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)) |
Uh oh!
There was an error while loading. Please reload this page.