我正在处理我的代码,我得到了其他语句的错误:
while i<=end:
x.append(i)
if i<=radiussph:
ex=((int(den(i)))*i)/(3*e)
else:
ex=((radiussph**3)*int(den(i)))/(3*(i**2)*e)
o.append(ex)
i+=10**(-5)
但是,一旦我删除它,追加语句就会得到错误。(实际上,根据模式,这一行代码-18正在得到一个语法错误。即使跳过了这一行,下一行也会出现同样的错误)。
完整代码:
from matplotlib import pyplot as plt
end=float(input("Enter the end point:"))**(10**(-3))
m=[i for i in range(0,int(end),2)]
def den(a):
for i in range(len(m)):
if a<m[i] and a>m[i-1]:
return (10-6*i)
if a==m[i]:
return (10-6*(i+1))
radiussph=float(input("Enter the radius of the sphere in millimetres:"))*(10**(-3))
o=[]
x=[]
i=1*10**(-5)
e=8.854*(10)**(-12)
while i<=end:
x.append(i)
if i<=radiussph:
ex=((int(den(i)))*i)/(3*e)
else:
ex=((radiussph**3)*int(den(i)))/(3*(i**2)*e)
o.append(ex)
i+=10**(-5)
plt.plot(x,o)
plt.show()
这是正在发生的,无论是在什么情况下。那么是什么导致了这个问题。
发布于 2022-04-17 12:15:35
这一行有一个不匹配的开括号.
ex=((int(den(i))*i)/(3*e)
# ^ There
你需要移除它或者在你需要的地方放一个关闭的
https://stackoverflow.com/questions/71901774
复制相似问题