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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With