为什么只循环了一次?
def square_of_sum(L):
sum = 0
for a in L:
a = a * a
sum = sum + a
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
输出结果是1 和 25,为什么只循环了一次?
def square_of_sum(L):
sum = 0
for a in L:
a = a * a
sum = sum + a
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
输出结果是1 和 25,为什么只循环了一次?
2019-10-31
举报