Skip to content

Commit 0a7d387

Browse files
TheRealDarkCodercclauss
authored andcommitted
Added a python script for finding sum of arithmetic series (TheAlgorithms#1279)
* Added a python script for finding sum of arithmetic series * Added some linting * Resolved comments * Fixed flake8 test
1 parent c4a9767 commit 0a7d387

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

maths/sum_of_arithmetic_series.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# DarkCoder
2+
def sum_of_series(first_term, common_diff, num_of_terms):
3+
"""
4+
Find the sum of n terms in an arithmetic progression.
5+
6+
>>> sum_of_series(1, 1, 10)
7+
55.0
8+
>>> sum_of_series(1, 10, 100)
9+
49600.0
10+
"""
11+
sum = ((num_of_terms/2)*(2*first_term+(num_of_terms-1)*common_diff))
12+
# formula for sum of series
13+
return sum
14+
15+
16+
def main():
17+
print(sum_of_series(1, 1, 10))
18+
19+
20+
if __name__ == "__main__":
21+
import doctest
22+
doctest.testmod()

0 commit comments

Comments
 (0)