Skip to content

Added a python script for finding sum of arithmetic series #1279

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 4 commits into from
Oct 6, 2019
Merged
Changes from all 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
22 changes: 22 additions & 0 deletions maths/sum_of_arithmetic_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# DarkCoder
def sum_of_series(first_term, common_diff, num_of_terms):
"""
Find the sum of n terms in an arithmetic progression.
>>> sum_of_series(1, 1, 10)
55.0
>>> sum_of_series(1, 10, 100)
49600.0
"""
sum = ((num_of_terms/2)*(2*first_term+(num_of_terms-1)*common_diff))
# formula for sum of series
return sum


def main():
print(sum_of_series(1, 1, 10))


if __name__ == "__main__":
import doctest
doctest.testmod()