programming-examples/python/Function/Python program to calculate the geometric sum of n-1.py
2019-11-15 12:59:38 +01:00

8 lines
176 B
Python

def geometric_sum(n):
if n < 0:
return 0
else:
return 1 / (pow(2, n)) + geometric_sum(n - 1)
print(geometric_sum(7))
print(geometric_sum(4))