CS 303e - Lab 6


For this project, you will write a program that checks the validity of ISBN numbers. This program will be submitted in file ISBN.py by 11 pm on the due date.

Problem Description: Most books are assigned a number called the international standard book number, or ISBN. This sequence typically contains 10 decimal digits, though sometimes the last digit is replaced with the capital letter X. Hyphens are sometimes embedded in between the digits to make the ISBN number more readable. The first nine digits uniquely identify a book, and the tenth character is a check digit that is used to verify the correctness of the first nine digits - the check digit is chosen so that a weighted sum calculated from digits of the ISBN number is divisible by 11. Since the check digits sometimes needs to be 10 in order to make this value divisible by 11, we use X to represent 10.

How to compute the weighted sums:
Form two lists of integers based on the digits in the ISBN. The first list, sum1, contains partial sums of the digits from the ISBN number. The second list, sum2, contains partial sums of the values in the sum1 list. The ISBN is correct if the last entry in sum2 is divisible by 11.

Example: Consider the ISBN number 0-321-53711-4. First, we remove (or ignore) the hyphens. So we get:

digits in ISBN 0 3 2 1 5 3 7 1 1 4
list sum1 entries 0 3 5 6 11 14 21 22 23 27
list sum2 entries 0 3 8 14 25 39 60 82 105 132


The ith entry in sum1 is the sum of the digits in positions 1 through i in the ISBN number, if you consider the leftmost digit to be in position 1.

The ith entry in sum2 is the sum of the integers in positions 1 through i in the sum1 list.

Since 132 is divisible by 11, the ISBN is valid.

Covered topics: functions, lists, file I/O, loops, string library functions.

You must use several functions to decompose the problem into smaller problems. All code except import statements and a call to main() must be contained in a function. No function should be very long or complicated, and each function should have a well-defined action.

Your program will process a file called isbn.txt that contains one ISBN per line. Some of the ISBNs will be valid, and some will be invalid. The ISBNs may contain one or more hyphens, and some of the invalid ISBNs may contain extra characters, or too few digits. The file that we will use to test your program will be different from the sample file. You will read one line at a time as a string, then store the digits (and possibly the character X) in a list. Do NOT include extraneous characters or hyphens in this list.  Note that the ISBN is invalid if:
You will use three lists in this project: One for the digits (and check character) in the ISBN number, one for the list sum1 described above, and another for sum2.

Open a file isbnValid.txt for writing, and write one line for each entry in the file isbn.txt. Each line should contain one ISBN number from the isbn.txt file, plus either the word "valid" or "invalid". For the sample isbn.txt file, isbnValid.txt looks like this:

0-321-53711-4   valid
-0-131-62959-X   valid
88-10001202   invalid
0--1014114578a-   invalid

Do not forget to open and close the input and output files.
You will submit your program in file ISBN.py by 11 pm on the due date.

Your program will be graded on correctness, documentation (comments to describe each code block), use of white space to improve readability, use of the correct program header, program decomposition (your use of functions to divide the problem into manageable pieces), quality of algorithm, use of meaningful variable and function names, adherence to coding style conventions that we have discussed in class, and readability of your code.



Notes:
1. The proctors will be grading this project. They will post a message to the yahoo group when he is finished grading and uploading project scores and project feedback (via turnin). Contact them first with any questions about grading.
2. If you submit this project late using slip days, you MUST email the proctors when you submit your project to let them know you are done.
3. This project is to be done individually. You should NOT
See the section of the syllabus on academic dishonesty. Look at the information on Moss, the plagiarism detection software, from the syllabus. Moss does an excellent job of detecting similarities in different programs. If you give your code to another student, you are as guilty of academic dishonesty as they are.  I am reminding you due to the many problems with academic dishonesty that have occurred this semester. 

4. Submit your project via turnin in file ISBN.py.