► Python program to print Arithmetic progression

Steps followed:

1. Take the first number, common difference and the number of items in progression as input from user

2. get last item of the sequence using below formula

Xn = a + d(n−1)

3. use range function to get the Arithmetic progression

Program

#Python program to print Arithmetic progression

# Take the first number, common difference and the number of items in progression as input from user

first_number = int(input("enter the first number of sequence: "))

common_difference = int(input("enter the common difference of the sequence: "))

items_in_sequence= int(input("enter the number of items to be printed in the sequence: "))

#get last item of the sequence

last_number = first_number + common_difference * (items_in_sequence-1)

# range function to get the Arithmetic progression

for i in range(first_number,last_number+1,common_difference):

print(i,end=",")

Output

enter the first number of sequence: 5

enter the common difference of the sequence: 6

enter the number of items to be printed in the sequence: 20

5,11,17,23,29,35,41,47,53,59,65,71,77,83,89,95,101,107,113,119

Also Read: