Loading

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)

使用列表解析使得代码更加简洁

posted @ 2023-03-13 10:37  Artwalker  阅读(22)  评论(0)    收藏  举报
Live2D