Dcoder icon

Sum of squares @ Dcoder

By Lochard | As a newbie programmer | 14 Jul 2023


Problem: Compute the sum of squares for the given numbers: a, a+1, ..., b-1, b.

Input: Two natural numbers a and b separated by a space.

Output: Computed sum: a*a + (a+1)*(a+1) + ... + (b-1)*(b-1) + b*b

Constraints: 1 <= a <= b <=100

Sample Input: 2 4

Sample Output: 

29

a, b = map(int, input().split())
print(sum(i**2 for i in range(a, b + 1)))

How do you rate this article?

1


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.