Python Program To Find Sum Of Arithmetic Progression Series

Python Program To Find Sum Of Arithmetic Progression Series

Everybody know about the “Arithmetic Progression Series” that is usually asked very frequently in maths subjects. So there are many popular questions on the AP(Arithmetic Progression) and finding the sum of AP is one of them. In this tutorial, we will solve this problem through python programming.

Before moving forward let’s study AP definition and basic formulas.

Definition: Arithmetic Progression (AP) is a series of numbers in a special order, in which the difference between any two consecutive terms is a fixed value. It is also called Arithmetic Sequence.

General Form Of Arithmetic Progression:

a, a + d, a + 2d, a + 3d, a + d,........, a + (n-1)d

 

 

Example:

Arithmetic Progression (AP) : 10, 20, 30, 40, 50 ......220

Useful Terms:

  • First Term(a) = 10
  • Nth Term(l) = 220
  • Common Difference(d) = 10

 

AP Formulas:

Find Nth Term of AP:

Tn = a + (n-1)d

Useful Terms:

  • a = First term of AP
  • Tn = Nth term of AP
  • d = Common difference
  • n = Position Of Term

 

Find Sum of AP: When last term is not given in AP Series.

S = (N/2)[2a + (n-1)d]

Useful Terms:

  • S = Sum of AP
  • a = First term of AP
  • d = Common difference
  • N = Total Number Of Terms In AP
  • n = Position Of the Term

 

Find Sum of AP: When the First(a) and last(l) terms are given with the total number of terms(N).

S = (N/2)[a + l]

Useful Terms:

  • S = Sum of AP
  • a = First term of AP
  • l = Last term of AP
  • N = Total Number Of Terms In AP

 

Arithmetic Progression Formulae Recap:

Arithmetic-Progression-Formulas

 

Method-01

When first term, common difference, nth term position and the total number of terms are given.

def sumOfAP(A,D,N):
    sumOFAP = (N/2)*(2*A + (N-1)*D)
    print("nArithmetic Progression Series sum is: ",sumOFAP)

a = int(input("Enter first element of AP: ", ))
d = int(input("Enter Common Difference Of AP: ", ))
n = int(input("Enter Total Number Element of AP: ", ))
sumOfAP(a,d,n)

Output:

Enter first element of AP: 1
Enter Common Difference Of AP: 1
Enter Total Number Element of AP: 12

Arithmetic Progression Series sum is:  78.0

 

Method-02

When the total number of elements, first and last terms are given.

def sumOfAP(A,L,N):
    sumOfAP = (N/2)*(A + L)
    print("nArithmetic Progression Series sum is: ",sumOfAP)

a = int(input("Enter first element of AP: ", ))
l = int(input("Enter Last Element of AP: ", ))
n = int(input("Enter Total Number Element of AP: ", ))
sumOfAP(a,l,n)

Output:

Enter first element of AP: 1
Enter Last Element of AP: 12
Enter Total Number Element of AP: 12

Arithmetic Progression Series sum is:  78.0

 

Method-03

when AP is given in list format.

def sumOfAP(N):
    APsum = 0
    for i in range(0,len(N)):
        APsum = APsum + N[i]
        
    print("Arithmetic Progression Series sum is: ",APsum)

# list01 = int(input("Enter the input: ", ))    
list01 = [10,20,30,40,50,60,70,80,90,100,110,120]
sumOfAP(list01)

Output:

Arithmetic Progression Series sum is:  780.0

 

Method-04

when AP is given in list format.

def sumOfAP(N):
    print("Arithmetic Progression Series sum is: ",(len(N))*(N[0]+N[-1])/2)

# list01 = int(input("Enter the input: ", ))    
list01 = [10,20,30,40,50,60,70,80,90,100,110,120]
sumOfAP(list01)

Output:

Arithmetic Progression Series sum is:  780.0

 

Leave a comment