Program to find Sum of a Series a ^ 1 / 1 ! + a ^ 2 / 2 ! + a ^ 3 / 3 ! + a ^ 4 / 4 ! + Ã ¢ â ‚¬¦ Ã ¢ â ‚¬¦ . + a ^ n / n ! | Python program to print the sum of series . function to calculate sum of given series . ; multiply ( a / i ) to previous term ; store result in res ; Driver code
from __future__ import division NEW_LINE def sumOfSeries ( a , num ) : NEW_LINE INDENT res = 0 NEW_LINE prev = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT prev *= ( a / i ) NEW_LINE res = res + prev NEW_LINE DEDENT return res NEW_LINE DEDENT n = 5 NEW_LINE a = 2 NEW_LINE print ( round ( sumOfSeries ( a , n ) , 4 ) ) NEW_LINE