Tell us what’s happening:
I don’t understand why this code doesn’t pass on the test 6.
Where should I fix in this code? How can I pass this case?
Your code so far
def verify_card_number(card_number: str):
numbers = [int(digit) for digit in card_number if digit.isdecimal()]
for index in range(len(numbers) - 2, -2, -2):
doubled = numbers[index] * 2
if doubled > 9:
doubled_str = str(doubled)
digit_sum = int(doubled_str[0]) + int(doubled_str[1])
numbers[index] = digit_sum
else:
numbers[index] = doubled
if sum(numbers) % 10 == 0:
return "VALID!"
else:
return "INVALID!"
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5 Safari/605.1.15
Challenge Information:
Implement the Luhn Algorithm - Implement the Luhn Algorithm