Square(n) Sum
Lancelot03
Posted on July 19, 2022
DESCRIPTION:
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.
Sample Tests-
import codewars_test as test
from solution import square_sum
@test.describe("Fixed Tests")
def basic_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
test.assert_equals(square_sum([1,2]), 5)
test.assert_equals(square_sum([0, 3, 4, 5]), 50)
test.assert_equals(square_sum([]), 0)
test.assert_equals(square_sum([-1,-2]), 5)
test.assert_equals(square_sum([-1,0,1]), 2)
Solution- ###Python
def square_sum(numbers):
a=[]
for i in range(len(numbers)):
a.append(numbers[i]**2)
return sum(a)
💖 💪 🙅 🚩
Lancelot03
Posted on July 19, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.