Having some trouble with a little bit of Python Homework:

  • Context: Python 
  • Thread starter Thread starter Spencero94
  • Start date Start date
  • Tags Tags
    Bit Homework Python
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 18K views
Spencero94
Messages
4
Reaction score
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
 
Physics news on Phys.org
Almost, just tweek it slightly.

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