Tell us what’s happening:
I’m having trouble understanding how running the string ‘4111-1111-1111-1111’ through this algorithm is supposed to return VALID as the output, since the resulting sum of 4+2+1+2+1+2+1+2+1+2+1+1 (with the last digit not being changed due to being a check digit) is not a multiple of 10. I’ve also noticed a significant difference in previous labs compared to current labs when looking for answers on other projects, have the courses been updated since feb 2026?
Your code so far
def verify_card_number(digits:str):
if '-' in digits:
digits = ''.join(digits.split('-'))
if ' ' in digits:
digits = ''.join(digits.split(' '))
print(digits)
dig_as_num = [int(num) for num in digits]
print(dig_as_num)
for i in range(1, len(dig_as_num)):
if i % 2 == 1 and i != len(dig_as_num) - 1:
dig_as_num[i] *= 2
if dig_as_num[i] > 9:
dig_as_num[i] = int(str(dig_as_num[i])[0]) + int(str(dig_as_num[i])[1])
print(dig_as_num)
total = 0
for i in dig_as_num:
total += i
print(total)
if total % 10 != 0:
return "INVALID!"
return "VALID!"
print(dig_as_num)
print(verify_card_number('4111-1111-1111-1111'))
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:149.0) Gecko/20100101 Firefox/149.0
Challenge Information:
Implement the Luhn Algorithm - Implement the Luhn Algorithm
