text: Program to find the sum of the series ( 1 / a + 2 / a ^ 2 + 3 / a ^ 3 + ... + n / a ^ n ) | Python 3 program to find the sum of the given series ; Function to return the sum of the series ; variable to store the answer ; Math . pow ( x , y ) returns x ^ y ; Driver code ; Print the sum of the series
code: import math NEW_LINE def getSum ( a , n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum += ( i / math . pow ( a , i ) ) ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT a = 3 ; n = 3 ; NEW_LINE print ( getSum ( a , n ) ) ; NEW_LINE