Spyder 中的无效语法错误?

Invalid Syntax error in Spyder?

runfile('C:/Users/kesha/untitled0.py', wdir='C:/Users/kesha')
File "C:/Users/kesha/untitled0.py", line 50
labely = 'Theta3'
     ^
SyntaxError: invalid syntax

我不明白将 'Theta3' 分配给 labely 变量有什么问题。将 'Theta2' 或 'Theta1' 分配给 labely 变量时没有错误。我很确定这也不是名称依赖,因为我没有成功切换名称。感谢您的时间和关注。

这是代码片段:

titleP = 'Amplitude of Pendulum vs. Time'
labelx = 'Time in Seconds'

labely = 'Theta1'
t,th1,E1 = calc(np.pi/12)
plot2d(labelx, labely, titleP, -1, 0, 1, t)

labely = 'Theta2'
t,th2,E2 = calc(np.pi/6)
plot2d(plot2d(labelx, labely, titleP, -1, 0, 1, t)

labely = 'Theta3'
t,th3,E3 = calc(np.pi/3)
plot2d(labelx, labely, titleP, -1, 0, 1, t)

您输入错误 labely = 'Theta2' 块。

plot2d(plot2d(labelx, labely, titleP, -1, 0, 1, t) 替换为 plot2d(labelx, labely, titleP, -1, 0, 1, t) 以解决错误。

titleP = 'Amplitude of Pendulum vs. Time'
labelx = 'Time in Seconds'

labely = 'Theta1'
t,th1,E1 = calc(np.pi/12)
plot2d(labelx, labely, titleP, -1, 0, 1, t)

labely = 'Theta2'
t,th2,E2 = calc(np.pi/6)
plot2d(labelx, labely, titleP, -1, 0, 1, t) # replaced

labely = 'Theta3'
t,th3,E3 = calc(np.pi/3)
plot2d(labelx, labely, titleP, -1, 0, 1, t)

缺少大括号...

# bad
plot2d(plot2d(labelx, labely, titleP, -1, 0, 1, t) # <= ")" is missing

# good
plot2d(labelx, labely, titleP, -1, 0, 1, t)