定义sum=0位置不同结果不同
def square_of_sum(L):
for x in L:
sum=0
sum=sum+x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
结果输出错误为25
def square_of_sum(L):
for x in L:
sum=0
sum=sum+x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
结果输出错误为25
2019-10-16
举报