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?
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
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…