runtime
110 / 500
question 110 String Algorithms · hard

ISBN-10 or ISBN-13?

A library catalogue accepts book numbers typed with or without hyphens and spaces. Decide whether a text is a valid ISBN-10, a valid ISBN-13, or neither, using the real check-digit rules.

ISBN-10: 10 characters; the first nine are digits and the last is a digit or X (meaning 10). Multiply the digits by 10, 9, 8, … 1 from left to right; the sum must be divisible by 11.

ISBN-13: 13 digits. Multiply them alternately by 1 and 3, starting with 1; the sum must be divisible by 10.

Functionisbn_kind(text)
Returns"ISBN-10", "ISBN-13", or None
Ignoredhyphens and spaces anywhere; a lower-case x counts as X (ISBN-10 only, last place only)
Examples
callisbn_kind('0-306-40615-2')returns'ISBN-10'
callisbn_kind('978-0-306-40615-7')returns'ISBN-13'
callisbn_kind('0-306-40615-3')returnsNone

Loading your progress…

ISBN-10 or ISBN-13? — Python practice · Runtime