Stuck on isbn verifier

def is_valid(isbn):
isbn_formula = 0
isbn_array =
isbn_new = “”

if "X" in isbn:
    isbn_new =  isbn.replace("X","10") 
    
if "-" in isbn:
    isbn_new =  isbn.replace("-","")
    
isbn_array = [int(x) for x in isbn_new]
digit = 10

for number in range(len(isbn_array)-1):
    isbn_formula += isbn_array[number]*digit
    digit -= 1

if isbn_formula % 11 == 0:
    return True
else:
    return False

I am stuck on this problem, it shows false when it should be true. I don’t know what I am missing

A couple of things:

if "X" in isbn:
    isbn_new =  isbn.replace("X","10") 

That will replace X anywhere in the string, but it’s not valid anywhere, only at the end.

It will replace it with the digits 1 and 0, not the value 10.

Is this Python? As a follow-on to @glennj comment above, you might want to take a look at the str.endswith string method, or using bracket notation on the string to grab the last codepoint:

if isbn[-1] == "X":
    isbn_new[-1] =  "10" 

Although, you can do a length check and a digit check if you’d rather do a mass replace:

    isbn_new = isbn.replace("-", "").replace("X", "10")

    if not isbn_new.isdigit() or len(isbn_new) < 10:
        return False

But that’s not going to solve all the problems.

You may also want to wait to convert the “numbers” later in the process, because as Glenn also points out, “10” will become 1 followed by 0…and that is going to screw up the math.

Remember, the final number is two digits long