Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sum of squares in a list in one line?

Tags:

People also ask

How do you write sum of squares in python?

FAQs Related to the Sum of Squares in Python (N*(N +1)*(2*N+1))/6 is the formula to calculate the sum of squares of n natural numbers. 2.

How do you find the square of a list in python?

To square a number list in python, it will square each number in the list and it will multiply each number by itself. After writing the above code (python square a number list), Ones you will print ” v**2 “ then the output will appear as a “ 1 9 25 49 ”. Here, the list will iterate and it will be multiplied by 2.

How do you print a square of n numbers in for loop in python?

for n in [0,1,2,3,4,5]: square = n**2 print(n,'squared is',square) print('The for loop is complete!


To demonstrate I have done sth. This is my code do sum in three lines.

l=[1,2,3,4,5];
sumOfList=0

for i in l:
    sumOfList+=i*i;
print sumOfList

I am curious can I do it in just one line?