Implement the Luhn Algorithm - Implement the Luhn Algorithm

Tell us what’s happening:

according to my maths, test 3 should provide invalid not valid.
3. verify_card_number(‘4111-1111-1111-1111’) should return VALID!.
can i get help on why its wrong i pass test 4 and 5 so the code is working

Your code so far

def verify_card_number(num):
    num= num.replace(" ", "").replace("-", "")
    num = list(num)
    num =[int(nu) for nu in num]
    total = 0
    print(num)
    for i,number in enumerate(num):
        if i%2:
            number=number*2
            if number>9:
                number= number-9
                total += number
                print(total)
            else:
                total += number
                print(total)
        else:
            total += number
            print(total)
    if total%10:
        return'INVALID!'
    else:
        return'VALID!'
             
print(verify_card_number('4111-1111-1111-1111'))
print(verify_card_number('453914889'))
print(verify_card_number('453914881'))
 



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36

Challenge Information:

Implement the Luhn Algorithm - Implement the Luhn Algorithm

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-luhn-algorithm/68507cadbf36aa089a84ce2d.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @samy_questions

Starting from the right …

Happy coding

You don’t need to include this code: