Python Forum
Invalid syntax error - need help fixing - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Invalid syntax error - need help fixing (/thread-32585.html)



Invalid syntax error - need help fixing - calgk01 - Feb-19-2021

j = 0
    while j < 36:
        A[j] = (0.04*(x[j]**2))+(0.04*(y[j]**2))
        print(type(A))
        B[j] = (x[j]**2)+(y[j]**2)
        C[j] = (0.01/(y[j]**2) 
        #Delta[j] = ((2*(math.sqrt((A[j] / B[j]) + C[j])))/Rsq[j])
        j += 1
Error:
runfile('C:/Users/ckirk/.spyder-py3/Labs semester 2 week 3/program.py', wdir='C:/Users/ckirk/.spyder-py3/Labs semester 2 week 3') File "C:\Users\ckirk\.spyder-py3\Labs semester 2 week 3\program.py", line 36 j += 1 ^ SyntaxError: invalid syntax
really don't understand why i'm getting an error here as earlier in the code I did the same thing (with different variables). It even does it for the Delta part (hence why I put it as a comment to try an debug)


RE: Invalid syntax error - need help fixing - Serafim - Feb-19-2021

A parenthese is missing on the line
C[j] = (0.01/(y[j]**2)
should be
C[j] = (0.01/(y[j]**2))
But please format youe code with tags in the future


RE: Invalid syntax error - need help fixing - calgk01 - Feb-19-2021

(Feb-19-2021, 11:10 AM)Serafim Wrote: A parenthese is missing on the line
C[j] = (0.01/(y[j]**2)
should be
C[j] = (0.01/(y[j]**2))
But please format youe code with tags in the future

oh god sorry Wall Wall I'm sorry i'm new here, I'll try to work out how to do it next time


RE: Invalid syntax error - need help fixing - nilamo - Feb-23-2021

This is a very common thing you'll see, btw. If there's a SyntaxError, but the line it's complaining about looks fine, then the issue is almost always a missing parenthesis on the previous line.