Daily Coding Challenge: ISBN-10 Validator

The challenge

Given a string, determine if it's a valid ISBN-10.

An ISBN-10 consists of hyphens ("-") and 10 other characters. After removing the hyphens ("-"):

The first 9 characters must be digits, and The final character may be a digit or the letter "X", which represents the number 10. To validate it:

Multiply each digit (or value) by its position (multiply the first digit by 1, the second by 2, and so on). Add all the results together. If the total is divisible by 11, it's valid.

🔗 https://www.freecodecamp.org/learn/daily-coding-challenge/2026-03-29

My solution

def is_valid_isbn10(string):
    new_string = "".join(string.split("-"))
    result = 0
    for index, char in enumerate(new_string):
        if char != "X":
            result += (index + 1) * int(char)
        if char == "X":
            result += (index + 1) * 10
    return result % 11 == 0

Author: Oscar Castillo-Felisola

Created: 2026-04-02 Thu 14:59