Feb-18-2020, 12:15 AM
Mostly the errors are in the indentation - making the loops not end where they should, and not zeroing out values when they should. This works.
import math def list_squared(m, n): final_list = [] for number in range(m, n+1): divisors_list = [] for i in range(1, number + 1): if number % i == 0: divisors_list.append(i) sum_of_divisors2 = 0 for divisor in divisors_list: divisors_squared = divisor ** 2 sum_of_divisors2 += divisors_squared if math.sqrt(sum_of_divisors2).is_integer() : final_list.append([number, sum_of_divisors2]) return final_list print(list_squared(5,1000))