Skip to content

Commit 5c68075

Browse files
committed
Finished working on the ISBN Verifier challenge
1 parent bddeb74 commit 5c68075

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
Binary file not shown.
Binary file not shown.

isbn-verifier/isbn_verifier.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
import re
2+
13
def is_valid(isbn):
2-
pass
4+
isbn = isbn.replace("-", "").replace(" ", "").upper();
5+
match = re.search(r'^(\d{9})(\d|X)$', isbn)
6+
if not match:
7+
return False
8+
9+
digits = match.group(1)
10+
check_digit = 10 if match.group(2) == 'X' else int(match.group(2))
11+
12+
result = sum((i + 1) * int(digit) for i, digit in enumerate(digits))
13+
return (result % 11) == check_digit

0 commit comments

Comments
 (0)