Geometric Series Sum

Calculate a + ar + ar² + ... + arⁿ.

IntermediatePhase 6 - Category 4: Mathematical CombinationsExample 5 of 10
geometric-series-sum.py
1# Take inputs
2a = float(input("Enter first term (a): "))
3r = float(input("Enter common ratio (r): "))
4n = int(input("Enter number of terms (n): "))
5
6# Calculate sum
7total = 0
8for i in range(n):
9 total += a * (r ** i)
10
11print(f"Sum: {total}")

Output

Enter first term (a): 2
Enter common ratio (r): 3
Enter number of terms (n): 4
Sum: 80.0

What's going on

Sum terms of geometric progression.

Key Concepts:

Each term = a * r^i
Loop from 0 to n-1
Accumulate sum