Tell us what’s happening:
I’m unable to satisfy test #6. It works with #7, but not #6. I’m not quite sure what to do next.
Your code so far
import re
findDigex = re.compile(r'\d+')
def verify_card_number(ccn):
ccn_int = [int(s) for s in findDigex.findall(ccn)] #Extracts all numbers from number to be verified
digits = [int(digit) for num in ccn_int for digit in str(num)] #separates all numbers into single values within a list
check_digit = digits[-1] #assigns the check digit
del digits[-1] #deletes the check digit from the end of digits
number_length = len(digits)
eval_nums = []
for index, num in enumerate(digits):
if number_length % 2 == 1:
if index % 2 == 0:
num = num * 2
if num >= 10:
num = (num // 10) + (num % 10)
eval_nums.append(num)
if number_length % 2 == 0:
if index % 2 == 1:
num = num * 2
if num >= 10:
num = (num // 10) + (num % 10)
eval_nums.append(num)
eval_nums.append(check_digit) #Re-add the check_digit back
check_sum = sum(eval_nums)
if check_sum % 10 == 0:
return 'VALID!'
else:
return 'INVALID!'
print(verify_card_number('4111-1111-1111-1111'))
print(verify_card_number('453914889'))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Challenge Information:
Implement the Luhn Algorithm - Implement the Luhn Algorithm