I have a code that reads 2 integers, m and n, and prints all the perfect numbers between m and n (inclusive m and n). If I input 2 and 7, it should give me 6. But it gives me 13. What went wrong?
m=int(input())
n=int(input())
myList=[]
for i in range(m,n+1):
for j in range(1,i):
if i%j==0:
myList.append(j)
sum=0
for i in range(0,len(myList)):
sum=sum+myList[i]
for j in range(m,n+1):
if sum==j:
sum=j
print(sum)