为什么必须要设置sum=o 然后用sum+sum + x * x,直接写x * x不可以吗
def square_of_sum(L): sum = 0 for x in L: sum = sum + x * x return sum print(square_of_sum([1, 2, 3, 4, 5])) print(square_of_sum([-5, 0, 5, 15, 25]))
def square_of_sum(L): sum = 0 for x in L: sum = sum + x * x return sum print(square_of_sum([1, 2, 3, 4, 5])) print(square_of_sum([-5, 0, 5, 15, 25]))
2023-10-17
举报