Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python: An arithmetic progression is a sequence of numbers in which the distance

ID: 3930504 • Letter: P

Question

Python: An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same. This in the sequence 1, 3, 5, 7, ..., the distance is 2 while in the sequence 6, 12, 18, 24, ..., the distance is 6. Given the positive integer distance and the integers m and n, create a list consisting of the arithmetic progression between (and including) m and n with a distance of distance (if m > n, the list should be empty.) For example, if distance is 2, m is 5, and n is 12, the list would be [5, 7, 9, 11]. Associate the list with the variable arith_prog.

Explanation / Answer


a=[]
m=int(raw_input(" Enter starting value m :"))
n=int(raw_input(" Enter ending value n :"))
d=int(raw_input(" Enter distance :"))
if m<n :
for i in range(m,n,d):
a.append(i)


print "list a looks like :-", a