In the ISBN-13 system, each book is assigned a unique 13-digit code. The first twelve digits identify the book itself, whereas the last digit merely serves as a check digit to detect invalid ISBN-13 codes.

ISBN
ISBN in text and barcode.

If $$x_1, \ldots, x_{12}$$ represent the first twelve digits of an ISBN-13 code, the check digit $$x_{13}$$ is computed as \[\begin{align} o &= x_1 + x_3 + x_5 + x_7 + x_9 + x_{11} \\ e &= x_2 + x_4 + x_6 + x_8 + x_{10} + x_{12} \\ x_{13} &= (10 - (o + 3e)\!\!\!\!\mod{10})\!\!\!\!\mod{10}\end{align}\] As a result, the check digit $$x_{13}$$ always takes a value in between 0 and 9, so that ISBN-13 codes only contain digits.

The website ISBNdb.com1 is a database of books. It provides a so-called Application Programming Interface2 (API) that allows computer programs to retrieve information about a particular book through its ISBN-13 code. We simulated this API for the purpose of this assignments (because the original API has become a paid service). For example, if you open the URL

a file will be downloaded with the following content

<?xml version="1.0" encoding="UTF-8"?>

<ISBNdb server_time="2012-11-19T07:28:26Z">
<BookList total_results="1" page_size="10" page_number="1" shown_results="1">
<BookData book_id="the_practice_of_computing_using_python" isbn="0136110673" isbn13="9780136110675">
<Title>The Practice of Computing using Python</Title>
<TitleLong></TitleLong>
<AuthorsText>William F Punch, Richard Enbody, </AuthorsText>
<PublisherText publisher_id="addison_wesley_a01">Addison Wesley</PublisherText>
</BookData>
</BookList>
</ISBNdb>

This is a file in XML format4. It contains a lot of information about the book, but for this assignment we are only interested in its title, authors and publishers. The most important part of the URL

is the part highlighted in red. At this location, you have to insert the ISBN-13 code of the book you wish to lookup information for.

Assignment

Write a function display_book_info that takes an ISBN-13 code (str). If the given ISBN-13 code is valid, the function must print the title, the authors and the publishers in the format you can derive from the example below. If the given ISBN-13 code is invalid, and error message must be printed as in the example below.

Example

>>> display_book_info('9780136110675')
Title: The Practice of Computing using Python
Authors: William F Punch, Richard Enbody
Publisher: Addison Wesley
>>> display_book_info('9780136110678')
Wrong ISBN-13 code

Ask Pythia …

In the following instruction video, Pythia explains how to tackle this assignment. Watch this video as a stepping stone to solve other exercises about text files6.

Note

The solution discussed in this video uses a different URL than the one that appears in the assignment. Apart from this, the rest of the solution remains valid as is.