lancelot03

Lancelot03

Posted on July 19, 2022

Square(n) Sum

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)
Enter fullscreen mode Exit fullscreen mode

Solution- ###Python

def square_sum(numbers):
    a=[]
    for i in range(len(numbers)):
        a.append(numbers[i]**2)
    return sum(a)
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
lancelot03
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.

Related

Square(n) Sum
beginners Square(n) Sum

July 19, 2022