#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Problem when starting a new line in for loop


    Hello,
    I'm using Python for an online course (And I'm a begginer to this language). I keep having the same problem. the code I'm trying to run is in the form of:
    for step in range(num_steps):
    i_ac=acceleration(x[step])
    Xe=x[step]+h*v[step]
    Ve=v[step]+h*acceleration(x[step])
    x[step + 1] = x[step] + h * (v[step]+Ve/2)
    v[step + 1] = v[step] + h * 0.5.*(i_ac+acceleration(Xe))

    The error in a general "SyntaxError:invalid syntax" in the last line starting with v[step+1]. It occures in the interface of the online course, as well as in komodo editor and begins as soon as I start writing this line. The error message corespond to the column of the letter v in the last line. I made sure that all the line starts on the same position. I incounter this problem repeatidaly and did't manage to pigure it out. I will be grateful for any idea.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    Originally Posted by itaiv
    Hello,
    I'm using Python for an online course (And I'm a begginer to this language). I keep having the same problem. the code I'm trying to run is in the form of:
    for step in range(num_steps):
    i_ac=acceleration(x[step])
    Xe=x[step]+h*v[step]
    Ve=v[step]+h*acceleration(x[step])
    x[step + 1] = x[step] + h * (v[step]+Ve/2)
    v[step + 1] = v[step] + h * 0.5.*(i_ac+acceleration(Xe))

    The error in a general "SyntaxError:invalid syntax" in the last line starting with v[step+1]. It occures in the interface of the online course, as well as in komodo editor and begins as soon as I start writing this line. The error message corespond to the column of the letter v in the last line. I made sure that all the line starts on the same position. I incounter this problem repeatidaly and did't manage to pigure it out. I will be grateful for any idea.
    First of all, use code tags so we don't have to take your word for it about the indentation.

    Second: 0.5.
    The trailing "." is incorrect.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,891
    Rep Power
    481
    0.5.*(

    See the extra "dot"? It appears in the line you high-lit red.

    Please follow the instructions at my signature to post python code. Preserving indentation is possible.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Thanks for your replays


    I thought I had a problem related to line breaks, sorry for the trouble

IMN logo majestic logo threadwatch logo seochat tools logo