I was working on my code and I got error for this else statement:
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)
But once I removed it the append statement is getting the error. (Actually by pattern, the line of code that lie in that line-18 is getting a Syntaxerror. Even after skipping that line I’m getting the same error in the next line).
Full code:
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()
This is happening irrespective of ide. So what causes this problem.
Advertisement
Answer
This line has a non-matched opened parenthesis.
ex=((int(den(i))*i)/(3*e) # ^ There
You’ll need to remove it or put a closing one where you need it