此代码在第一个 for 循环上显示"invalid syntax"错误


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)

第四行缺少括号

list( map ( int, input().split() ) )

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)

相关内容

最新更新