def compare(A: object, B: object) -> object:
if(A>B):
return A
elif(A<B):
return B
else:
return A
if __name__ == "__main__":
A = int(input())
scorelist = []
for i in range(0,A):
tmp = int(input())
scorelist.append(tmp)
sum =+ int(scorelist[0])
k = 1
for j in A-2:
D = compare(scorelist[k],scorelist[k+1]
k = scorelist.index(D)
sum =+ D
print (sum)
print(scorelist)
scorelist
是未解决的参考,我不知道为什么不能使用“ k
”。
line 22
k = scorelist.index(D)
^
SyntaxError: invalid syntax
答案 0 :(得分:0)
您缺少右括号:
def compare(A: object, B: object) -> object:
if(A>B):
return A
elif(A<B):
return B
else:
return A
if __name__ == "__main__":
A = int(input())
scorelist = []
for i in range(0,A):
tmp = int(input())
scorelist.append(tmp)
sum =+ int(scorelist[0])
k = 1
for j in A-2:
D = compare(scorelist[k],scorelist[k+1])
k = scorelist.index(D)
sum =+ D
print (sum)
print(scorelist)