- #1
Spencero94
- 4
- 0
Homework Statement
The problem shows as follows:
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 positive integer n , associate the variable sum with the sum of the elements of the arithmetic progression from 1 to n with distance distance . For example, if distance is 2 and n is 10 , then sum would be associated with 25 because 1+3+5+7+9 = 25 .
Homework Equations
This is definitely a "for" statement, and distance is added to a given integer i within the range of (1,n)
The Attempt at a Solution
So far i have the following written, but it seems to be telling me to use a "+" sign somewhere in my script:
sum = 0
i = 1
for i in range (1, n):
i += distance
sum += i