Sum of Arithmetic Geometric Sequence | Python3 code to find the sum of first n terms . ; Return the sum of first n term of AGP ; finding the each term of AGP and adding it to sum . ; Driven Code
import math NEW_LINE def sumofNterm ( a , d , b , r , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum += ( ( a + ( i - 1 ) * d ) * ( b * math . pow ( r , i - 1 ) ) ) NEW_LINE DEDENT return int ( sum ) NEW_LINE DEDENT a = 1 NEW_LINE d = 1 NEW_LINE b = 2 NEW_LINE r = 2 NEW_LINE n = 3 NEW_LINE print ( sumofNterm ( a , d , b , r , n ) ) NEW_LINE