89.8k views
5 votes
Calculate the sum of squares of given input of numbers

User Peetasan
by
8.1k points

1 Answer

3 votes

Answer:

Here is a Python function to calculate the sum of squares of a list of numbers:

python

Copy code

def sum_of_squares(numbers):

return sum([x**2 for x in numbers])

You can use this function by passing a list of numbers as an argument:

scss

Copy code

numbers = [1, 2, 3, 4, 5]

result = sum_of_squares(numbers)

print(result) # Output: 55 (1^2 + 2^2 + 3^2 + 4^2 + 5^2)

Step-by-step explanation:

User Jongwoo
by
8.5k points