我真的很困惑。我一直在处理下面的代码(并附上图片) - 我一直收到行print myList[i],' ',
的语法错误
我认为这与括号有关,但我不确定。任何帮助表示赞赏!
def SwapFirstAndLast(list):
temp = list[len(list)-1]
list[len(list)-1] = list[0]
list[0] = temp
def ReplaceEvensWithZeros(list):
for i in range(len(list)):
if(list[i] % 2 == 0):
list[i] = 0
#Initializes a list with ten random integers
import random
myList=[]
for i in range(10):
myList.append(random.randrange(1,101,1))
#- every element at an even index
for i in range(0, len(myList), 2):
print myList[i],' ',
#- every even element
print
for i in range(len(myList)):
if myList[i] % 2 == 0:
print myList[i],' ',
#- all elements in reverse order
print
print myList[::-1]
#- only the first and last element.
print myList[-1:], ' ', myList[:1]
答案 0 :(得分:0)
您的语法错误应该是这样的:
IndentationError: unindent does not match any outer indentation level
它告诉您没有正确格式化代码。 Python使用缩进来构造代码逻辑。请遵守规则。