MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / sum_of_series

Function sum_of_series

maths/sum_of_arithmetic_series.py:2–13  ·  view source on GitHub ↗

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

(first_term: int, common_diff: int, num_of_terms: int)

Source from the content-addressed store, hash-verified

1# DarkCoder
2def sum_of_series(first_term: int, common_diff: int, num_of_terms: int) -> float:
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 total = (num_of_terms / 2) * (2 * first_term + (num_of_terms - 1) * common_diff)
12 # formula for sum of series
13 return total
14
15
16def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected