Implement the Luhn Algorithm - Invalid test (4111-1111-1111-1111)

Tell us what’s happening:

The card number 4111-1111-1111-1111 is a invalid number I test it by following the steps shown in the instructions.
But there is a test that wants this number to be valid
I tried to create a special case but that doesn’t work.
So how do I deal with this apparent paradox? Am I doing something wrong?

(there are some print() functions to follow the code)

Your code so far

def verify_card_number(digits):
    #stringify
    digits = str(digits)

    #clean up
    digits = digits.replace("-","")
    digits = digits.replace(" ","")

    #confirm
    if not digits.isdigit():
        raise TypeError ("The card number should only contain digits")
    
    #verify
    last_digit = digits[-1]
    print(f"The last digit is {last_digit}")
    remain_digits = digits[:-1]
    print(f"The remain digits are {remain_digits}")
    

    digit_sum = int(last_digit)
    position = 0
    for digit in remain_digits:
        print(f"For position {position} the number were {digit}")
        if position/2 == position//2:
            number = int(digit)
        else:
            number = str(int(digit)*2)
            if len(number)>1:
                number= int(number[0]) + int(number[1])
            else:
                number = int(number)
        print(f"The number became {number}")
        position +=1
        digit_sum  += number
        print(f"On goin sum:{digit_sum}")

    if digit_sum/10 == digit_sum//10:
        return "VALID!"
    else:
        return "INVALID!"

#print(verify_card_number("4   5   3   9   1   4   8   8   1"))
#print(verify_card_number("453914889"))
print(verify_card_number("4111-1111-1111-1111"))
#print(verify_card_number("1234 5678 9012 3456"))

    




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.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

the number is valid

let’s do it:

4111-1111-1111-1111

  • Starting from the right, and excluding the rightmost digit (the check digit), double the value of every other digit.

8121-2121-2121-2121

  • If the result of doubling a digit is greater than 9, sum the digits to get a single digit. Alternatively, you can subtract 9 from the result.

this does not apply

  • Take the sum of all the digits including the check digit.

8+1+2+1+2+1+2+1+2+1+2+1+2+1+2+1 = 30

  • If the sum of all the digits is a multiple of 10, then the number is valid; else it is not valid.

result, it’s valid

In this case you are multiplying by 2 the first digit that appears. In the instructions they multiply the second digit (shown bellow)

Account number      4   5   3   9   1   4   8   8   1 
Double every other  4  10   3  18   1   8   8  16   1 
Sum 2-char digits   4   1   3   9   1   8   8   7   1  

Also changing the multiplying order invalidates the “453914889” test, that also should return valid

I am following the same algorithm shown there.

please notice “starting from the right”
so that measn you always avoid the last digit, double the second to last, skip the third to last, double the fourth to last…