Skip to content

Instantly share code, notes, and snippets.

@aahnik
Created July 13, 2020 14:47
Show Gist options
  • Save aahnik/fbd695a460bbf59b931639b24e3fcfc0 to your computer and use it in GitHub Desktop.
Save aahnik/fbd695a460bbf59b931639b24e3fcfc0 to your computer and use it in GitHub Desktop.
# General Term (x ** power)/factorial(power)
# where power ranges from 0 to n-1 if the series has n terms
def factorial(num):
# recursive function
if num == 0:
# base case
return 1
else:
return num * factorial(num - 1)
def find_sum(x, n):
# here n is the no of terms in series, and x is given value
sum = 0
for power in range(n):
sum += (x ** power) / factorial(power)
print(f"the required sum is {sum}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment