# Homework Help: Having some trouble with a little bit of Python Homework:

1. Feb 8, 2014

### Spencero94

1. The problem statement, all variables and given/known data
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 .

2. Relevant equations

This is definitely a "for" statement, and distance is added to a given integer i within the range of (1,n)

3. 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

2. Feb 8, 2014

### ShayanJ

Code (Text):

sum=0
for i in range (1,n,distance):
sum+=i

3. Nov 29, 2014

### Brie

Almost, just tweek it slightly.

sum=0
for i in range(1,n+1,distance):
sum += i

viola!