PROG0033 - ISBN

no tags 

In the ISBN-10 (International Standard Book Numbering) system that was used until the end of 2006, each book is assigned a unique 10-digit code. The first nine digits uniquely identify the book itself, whereas the last digit merely serves as a check digit to detect invalid ISBN-10 codes.

ISBN
ISBN in text and barcode

If $x_1, \ldots, x_9$ represent the first nine digits of an ISBN-10 code, the check digit $x_{10}$ is calculated as $$x_{10} = (x_1+ 2x_2+ 3x_3+ 4x_4+ 5x_5+ 6x_6+ 7x_7+ 8x_8+ 9x_9)\!\!\!\!\mod{11}\,.$$ As a result, $x_{10}$ always takes a value in between 0 and 10. If the check digit is equal to 10, it is represented in the ISBN-10 code by the capital letter X. The digits of an ISBN-10 code are subdivided into four groups separated by dashes (-). The first and the last group each contain a single digit, whereas the two middle groups each contain four digits.

Assignment

Write a function isISBN that takes a single string argument. The function must return a Boolean value that indicates whether or not the argument represents a valid ISBN-10 code. A valid ISBN-10 code is a string having 10 characters, has a correct check digit and has its digits grouped in the proper way.

Example

>>> isISBN('9-9715-0210-0')
True
>>> isISBN('997-150-210-0')
False
>>> isISBN('9-9715-0210-8')
False

Binnen het ISBN-10 (International Standard Book Numbering) systeem dat tot eind 2006 gebruikt werd, kreeg elk boek een unieke code toegewezen die bestaat uit 10 cijfers. De eerste 9 daarvan geven informatie over het boek zelf, terwijl het laatste louter een controlecijfer is dat dient om foutieve ISBN-10 codes te detecteren.

ISBN
ISBN in tekst en streepjescode

Indien $x_1, \ldots, x_9$ de eerste 9 cijfers van een ISBN-10 code voorstellen, dan wordt het controlecijfer $x_{10}$ als volgt berekend: $$x_{10} = (x_1+ 2x_2+ 3x_3+ 4x_4+ 5x_5+ 6x_6+ 7x_7+ 8x_8+ 9x_9)\!\!\!\!\mod{11}$$ $x_{10}$ kan m.a.w. de waarden 0 tot en met 10 aannemen. Indien het controlecijfer gelijk is aan 10, dan wordt dit in de ISBN-10 code genoteerd als de hoofdletter X. De cijfers van een ISBN-10 code worden verder opgedeeld in vier groepen, die van elkaar gescheiden worden door een koppelteken. De eerste en laatste groep bestaan telkens uit één cijfer, terwijl de twee middelste groepen elk uit vier cijfers bestaan.

Opgave

Schrijf een functie isISBN waaraan een string moet doorgegeven worden die een ISBN-10 code voorstelt. De functie moet als resultaat een Booleaanse waarde teruggeven die aangeeft of dit een geldige ISBN-10 code voorstelt of niet. Een geldige ISBN-10 code is een string van 10 karakters, heeft een correct controlecijfer en is opgedeeld in groepen zoals hierboven staat beschreven.

Voorbeeld

>>> isISBN('9-9715-0210-0')
True
>>> isISBN('997-150-210-0')
False
>>> isISBN('9-9715-0210-8')
False


Added by:Peter Dawyndt
Date:2011-07-22
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None