n=int(input())
ls=[]
ls2=[]
ls=list(map(int,input().split())
for i in range (n): # here the compiler is showing invalid syntax
if ls[i]==0:
ls2.append(i)
for j in range(n-2):
if ls2[j]+2 in ls2:
ls3.append(ls[j]+2)
print(ls3)
您在第四行上缺少括号
n=int(input())
ls=[]
ls2=[]
ls=list(map(int,input().split()))
# ^
#You were missing a paranthese
for i in range (n): # here the compiler is showing invalid syntax
if ls[i]==0:
ls2.append(i)
for j in range(n-2):
if ls2[j]+2 in ls2:
ls3.append(ls[j]+2)
print(ls3)