
Shuvam C. answered 05/23/22
Tutor
4.7
(44)
Dedicated Tutor & CS Major at University of Michigan
This problem can be solved with a short for loop in Python by iterating from m to n using the range function. I'm assuming that you want n's square to be included in the sum, which is why I used n+1 in the range. Here's how I would code it:
def sum_of_squares_m_to_n(m, n):
sum = 0
for i in range(m, n + 1):
sum += i**2
return sum