我在(return not alternative)遇到问题。错误是“空格使用不一致”。有人能帮我吗。 我尝试使用适当数量的制表符和空格,但问题仍然存在。你知道吗
def alternating(list):
listDifference = []
if list == []:
return True
alternating = True
lPos = 0
rPos = 1
#appends the difference between values to a new lis
while (lPos < len(list)-1) and (rPos < len(list)):
listDifference.append(list[lPos] - list[rPos])
lPos += 1
rPos += 1
#resets the position
lPos,rPos = 0,1
#checks whether values are alternating or not
while (lPos < len(listDifference)-1) and (rPos < len(listDifference)):
if listDifference[lPos] < 0:
if listDifference[rPos] > 0:
lPos += 1
rPos += 1
else:
return not alternating
elif listDifference[lPos] > 0:
if listDifference[rPos] < 0:
lPos += 1
rPos += 1
else:
return not alternating
return alternating
您的问题是,您同时使用制表符和空格,这会产生错误,因此您只需要使用制表符或空格。你知道吗
相关问题 更多 >
编程相关推荐