Sum of Squares from M to N | Python Programs using Functions

 

Sum of Squares from M to N

Write a function with name sum_of_squaresm_to_n that takes two integers (M and N) and sum the squares from M to N.

Input

The first line of input will contain an integer (M).
The second line of input will contain an integer (N).

Output

The output should be a single line containing the sum of the squares from M to N.

Explanation

For example, if the given M is 3 and N is 5, the sum of squares of 3, 4 and 5 is 50. So the output should be 50.

Sample Input 1
3
5

Sample Output 1
50

Sample Input 2
1
4

Sample Output 2
30

Code:

def sum_of_squares_m_to_n(m, n):
    sum=0
    for i in range(m,n+1):
        sum+=i**2
    return sum

m = int(input())
n = int(input())
result=sum_of_squares_m_to_n(m,n)
print(result)

Input
15
35

Output
13895

Comments

Popular posts from this blog

CODING ASSIGNMENT 4

CODING PRACTICE 11 Music Page

CODING ASSIGNMENT 3