Plz help in this code

I’ve been working on this problem in CodeWars and I cannot find where I am going wrong.

import math

def retListSquare(a):
    squares = []
    for i in a:
    return squares

def findDivisor(a):
    factors = []
    for i in range(1, a+1):
        if a % i == 0:
    return factors
def list_squared(m, n):
	ans = []
	r = range(m, n+1)
	for i in r:
		Sum = sum(retListSquare(findDivisor(i)))
		if int(Sum + 0.5) ** 2 == Sum:
			j = []
	return ans

print(list_squared(42, 250))  # Returns '[]'

How could this condition ever evaluate to true? Since it can’t, ans remains an empty list.
P.S. I love Codewars!

I think this is more like what you’re trying to do. Checking to see if Sum is a perfect square? There may be another way, but this will work:

if math.sqrt(Sum) == int(math.sqrt(Sum)): 

Good luck! :slightly_smiling_face:

1 Like

if math.sqrt(Sum) % 1 == 0 will do what you want.

Also, to return a list of factors of a number n, you need only range as high as the square root of n.

1 Like

3 posts were split to a new topic: Segue on a perfect topic

Yeah I was a little confused in the square root thing. Thank mate :+1:

I love CodeWars too! I’m learning Python so trying to solve problems for practice :slight_smile: