I was working on my code and I got error for this else statement:
JavaScript
x
9
1
while i<=end:
2
x.append(i)
3
if i<=radiussph:
4
ex=((int(den(i)))*i)/(3*e)
5
else:
6
ex=((radiussph**3)*int(den(i)))/(3*(i**2)*e)
7
o.append(ex)
8
i+=10**(-5)
9
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:
JavaScript
1
26
26
1
from matplotlib import pyplot as plt
2
3
end=float(input("Enter the end point:"))**(10**(-3))
4
m=[i for i in range(0,int(end),2)]
5
def den(a):
6
for i in range(len(m)):
7
if a<m[i] and a>m[i-1]:
8
return (10-6*i)
9
if a==m[i]:
10
return (10-6*(i+1))
11
radiussph=float(input("Enter the radius of the sphere in millimetres:"))*(10**(-3))
12
o=[]
13
x=[]
14
i=1*10**(-5)
15
e=8.854*(10)**(-12)
16
while i<=end:
17
x.append(i)
18
if i<=radiussph:
19
ex=((int(den(i)))*i)/(3*e)
20
else:
21
ex=((radiussph**3)*int(den(i)))/(3*(i**2)*e)
22
o.append(ex)
23
i+=10**(-5)
24
plt.plot(x,o)
25
plt.show()
26
This is happening irrespective of ide. So what causes this problem.
Advertisement
Answer
This line has a non-matched opened parenthesis.
JavaScript
1
3
1
ex=((int(den(i))*i)/(3*e)
2
# ^ There
3
You’ll need to remove it or put a closing one where you need it