Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
Pmax = float(max([P1, P2]))
Tr=T/self.typeMolecule.Tc
w=0.5*(1+scipy.tanh((10**5)*(Tr-0.6)))
fi1=0.5*(1-scipy.tanh(8*((Tr**0.4)-1)))
fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494
guess = Pmin+(Pmax-Pmin)*((1-w**2)*fi1+(w**2)*fi2) # error here
solution = scipy.optimize.newton(funcPsat,guess, args=(T,self))
On the marked line of code,
guess = Pmin+(Pmax-Pmin)*((1-w**2)*fi1+(w**2)*fi2)
, I get an error message:
SyntaxError: invalid syntax
.
Pmin
,
Pmax
,
w
,
fi1
and
fi2
have all been assigned at this point, so why is there an error?
When I remove that line from the code, the same error appears at the next line of code, again for no apparent reason.
–
–
–
–
When an error is reported on a line that appears correct, try removing (or commenting out) the line where the error appears to be. If the error moves to the next line, there are two possibilities:
Either
both
lines have a problem (and the second may have been hidden by the first); or
The
previous
line has a problem which is being carried forward.
The latter is
more likely
, especially if removing another line causes the error to move again.
For example, code like the following, saved as
twisty_passages.py
:
xyzzy = (1 +
plugh = 7
will produce an error on line 2, even though the problem is clearly caused by line 1:
File "twisty_passages.py", line 2
plugh = 7
SyntaxError: invalid syntax
The code in the question has a similar problem: the code on the previous line has unbalanced parentheses. Annotated to make it clearer:
# open parentheses: 1 2 3
# v v v
fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494
# ^ ^
# close parentheses: 1 2
There isn't really a general solution for this - the code needs to be analyzed and understood, in order to determine how the parentheses should be altered.
You're missing a close paren in this line:
fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494
There are three (
and only two )
.
–
I noticed that invalid syntax error for no apparent reason can be caused by using space in:
print(f'{something something}')
Python IDLE seems to jump and highlight a part of the first line for some reason (even if the first line happens to be a comment), which is misleading.
–