Write a Python Program to Calculate Geometric Sum Of N-1

Write a python program to calculate the geometric sum of n-1. is provided on this page.

Write A Python Program To Calculate The Geometric Sum Of N-1.

In mathematics, a geometric series is a series with a constant ratio between successive terms.


def calculate_geometric_sum(n):
  if n < 0:
    return 0
  else:
    return 1 / (pow(2, n)) + calculate_geometric_sum(n - 1)


print(calculate_geometric_sum(10))
print(calculate_geometric_sum(22))

Output

1.9990234375
1.999999761581421

Related To Python

Comments