def ap_sum(a,n,d): total = (n * (2 * a + (n - 1) * d)) / 2 return total