Question
PYTHON - Using functions -can't use map, panda, sys or any other type of import other than math Every book is identified by a 10-character
PYTHON
- Using functions
-can't use map, panda, sys or any other type of import other than math
Every book is identified by a 10-character International Standard Book Number (ISBN), which is
usually printed on the back cover of the book. The first nine characters are digits and the last
character is either a digit or the letter X (which stands for ten). Three examples of ISBNs are 0-13-
030657-6, 0-32-108599-X, and 0-471-58719-2. The hyphens separate the characters into four
blocks.
The first block usually consists of a single digit and identifies the language (0 for English, 2 for
French, 3 for German, etc.). The second block identifies the publisher. The third block is the
number the publisher has chosen for the book. The fourth block, which always consists of a
single character called the check digit, is used to test for errors.
Lets refer to the 10 characters of the ISBN as d1,d2,d3,d4,d5,d6,d7,d8,d9,d1, d2, d3, d4, d5, d6, d7, d8, d9, and d10. The check digit is chosen so that the sum 10*d1 + 9* d2 + 8*d3 + 7*d4 + 6*d5 + 5*d6 + 4*d7 + 3*d8 + 2*d9 + 1*d10(*)
is a multiple of 11. If the last character of the ISBN is an X, then in the sum (*) is replaced with 10.
For example, with the ISBN 0-32-108599-X, the sum would be
10*0 + 9*3 + 8*2 + 7*1 + 6*0 + 5*8 + 4 *5 + 3*9 + 2*9 +10*1 = 165
Since 10*0 + 9*3 + 8*2 + 7*1 + 6*0 + 5*8 + 4 *5 + 3*9 + 2*9 +10*1 = 165
is 165, the sum is a multiple of 11
This checking scheme will detect every single digit and transposition-of-adjacent-digits error.
That is, if while copying an ISBN number you miscopy a single character or transpose two
adjacent characters, then the sum will no longer be a multiple of 11.
Input
You will be given a list with isbns: one per each line. You will need to ask the user running your
program for the specific filenames, but what we do know is that each file will be saved as a txt
file, with one isbn per file line.
.
This is the sample run of the beginning of the program (yellow highlighting indicate possible user
input):
Enter the name of the file with isbns: isbns.txt
Requirements
Your ISBN is invalid If the count of the number of characters is not equal to 13
If any of the characters are not digits other than the last character which can be an X and a hyphen
If there arent enough digits
If the country code is not between 0 and 9
If the sum isnt a multiple of 11
Output
Your program has to generate a report as a csv file, called
isbnresults.csv
. The report has to
contain all isbns that appear on the list, sum, and their validity. Examine and follow the format of
the provided sample output file.
You must test for other cases as this file doesnt contain every
possible case.
Your program
must also
output the following (same as the csv file) on the interactive output
when it is run. Dont include asterisks in your output.
**************************************************
Sum is 110
The ISBN: 0-13-030657-6 is valid
Sum is 165
The ISBN: 0-32-108599-X is valid
Sum is 219
The ISBN: 0-471-58719-1 is invalid
**************************************************
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started