finding the each term of AGP and adding it to sum .
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