Possible Luhn error

My solution for Luhn passes all test but 4, 10 and 11. I have passed it through and IDE and return True for these tests but exercism says they return False. Can anyone see where I am going wrong if at all before I give up and move on to the next?

class Luhn:
def init(self, card_num):
self.card_num = (card_num)
self.number_valid = self.valid()

def valid(self):
    self.number_valid = True
    self.card_num = self.card_num.replace(" ", "")
    
    if len(self.card_num) < 2 or self.card_num.isdigit() == False:
        self.number_valid = False
        return self.number_valid
    self.card_num = (self.card_num)[::-1]

    doubled = 0
    for i, num in enumerate(self.card_num):
        n = int(num)
        if i % 2 == 1:
            n *= 2
            if n > 9:
                n -= 9
        doubled += n

    if doubled % 10 == 0:
        return self.number_valid
    self.number_valid = False
    return self.number_valid

Don’t make us go look it up: what are the inputs for those failing tests?

Sorry! Tests are:

“59”

“095 245 88”

“234 567 891 234”

Your code returns False because of the above code block.

Is it possible to give more details?

I have tried commenting out various parts of that code block without any change to the 3 test results.

I have ran is through the IDE here Python Tutor code visualizer: Visualize code in Python, JavaScript, C, C++, and Java

and the 3 tests return True so I am lost!

What is "095 245 88".is digit()?

Maybe I am missing something. I am new to this after all. But my understanding is that
“095 245 88”.is digit() would return False due to the spaces but that shouldn’t be a problem due the line in the block above being

self.card_num = self.card_num.replace(" ", “”)

Which should, and has on everywhere ive checked except exercism, return True.

Also that would not account for “59” failing.

Its possible, and probable im missing something obvious…

In your valid function, you do this

self.card_num = (self.card_num)[::-1]

where you overwrite the instance variable with its reverse value.

The tests create an instance and then call valid()

However in your constructor you do this

self.number_valid = self.valid()

You end up reversing the card number twice.

Remove that line from __init__