Square(n) Sum
Instructions
Complete the square sum function so that it squares each number passed into it and then sums the results together.
For example, for[1, 2, 2] it should return 9 because 1^2 + 2^2 +2^2 = 9
Solution
def square_sum(numbers):
return sum(value**2 for value in numbers)
使用列表解析使得代码更加简洁
人生便是艺术。

浙公网安备 33010602011771号