Why am i receiving "list" object cannot be interpreted as an integer and how to solve this problem?

The following code is an attempt of mine to solve the problem 4 of euler project.
However i am not looking for the problem’s solution in this topic.
My problem is that whenever i try to print the following, it throws me an error like so:

list" object cannot be interpreted as an integer.

l = list(range(0, 998002))    # the number "998002" is the largest number that can be produced by multiplying 
                                                 two 3-digit numbers.

def palindrome():
    for a in range(l):             # the problem seems to be in the foor loop....
        for b in (l):               
            pal = a * b
            x = str(pal)
            y = str(a)
            z = str(b)
            if y == 3 and z == 3 and x[0:len(pal)] == x[::-1]:
                return pal        

Can someone please explain me why that’s happening?
Also, i’d really appreciate any suggestions on how to tuckle this issue.

1 Like

int objects have no length attribute.

Is your progrram attempting find all palidromes that are the product of two three digit numbers? Or to just test if a product of two numbers is a palindrome?

A simple way to test if a number is not three digits is,

x not in range(100, 1000)

which will give True is x is less than or greater than three digits.

1 Like

mtf, thank you for your advice it really helped me out!!!