为什么我会得到这个 while 循环的 Syntaxerror?
Why am I getting Syntaxerror for this while loop?
我正在处理我的代码,但我遇到了这个 else 语句的错误:
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()
这与 ide 无关。那么是什么导致了这个问题。
这一行有一个 non-matched 左括号。
ex=((int(den(i))*i)/(3*e)
# ^ There
您需要将其移除或在您需要的地方放置一个结尾
我正在处理我的代码,但我遇到了这个 else 语句的错误:
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()
这与 ide 无关。那么是什么导致了这个问题。
这一行有一个 non-matched 左括号。
ex=((int(den(i))*i)/(3*e)
# ^ There
您需要将其移除或在您需要的地方放置一个结尾