Untitled
unknown
python
a year ago
459 B
6
Indexable
def is_valid(isbn): isbn = isbn.replace("-", "") if len(isbn) != 10 or (isbn[-1] != "X" and not isbn[-1].isnumeric()): return False check = isbn[-1] if check == "X": check = 10 else: check = int(check) sum = 0 for i, digit in enumerate(isbn[:-1]): if not digit.isnumeric(): return False sum += int(digit) * (10 - i) return True if ((sum + check) % 11) == 0 else False
Editor is loading...
Leave a Comment