Python代写:CPSC111 ISBN Validator

代写一个ISBN码的校验器,识别ISBN的合法性。

Notice

As always, all your answers should use functions and every function should have a documentation string explaining the purpose of the function. Use the Python template given below at the top of your program you submit (don’t forget to modify it to include your information; your name and your student number etc)

Do not wait until the last minute to do this project in case you run into problems.

Background

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 digit may need to be 10 to make this value divisible by 11, X (or x) is used to represent 10.

For this project, you will write a program that checks the validity of ISBN numbers.You must use several functions to decompose the problem into smaller problems.No function should be very long or complicated, and each function should have a well-defined action.

Note: You may not use any programming construct that we have not covered in class. You may not use global variables.

File Name: ISBN.py

Your program will process a file called “isbn.txt” that contains one ISBN per line. Although the file that we will use to test your program will also be named “isbn.txt”, it will not have the same content. For each ISBN, you need to determine whether it is valid. Note that the ISBN is invalid if:

  • there are characters other than the digits ‘0’ through ‘9’ and the characters ‘x’, ‘X’, and ‘-‘,
  • if there is an ‘x’ or ‘X’ before the last character
  • if there are not exactly 9 digits before the last character,
  • if the last character (other than a hyphen) is not a digit from 0 to 9, ‘x’ or ‘X’.

Valid ISBNs may contain one or more hyphens at any location in the number.

Additionally, you must calculate weighted sums described in the first paragraph to determine an ISBN’s validity. In your program,you must accomplish this using three lists: one for the digits (and check character) in the ISBN number, and one for each of the weighted sums.

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.

Carefully consider the following example.

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.

Write the results of each ISBN to the file isbnValid.txt using one line for each entry in the input file. 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.

Test your program by using at least 5 additional test cases (you may add them to the end of “isbn.txt”). Put your test cases and their result in comments at the end of your .py file

Name your file ISBN.py. Be certain to begin your file with the following header:

1
2
3
4
5
6
7
8
9
10
11
# File: --name of file--
# Description: --a description of your program--
# Final Project:
#
# Name: --your name--
# StudentID: --your id--
# Course Name: CPSC111 Section --your section--
#
# Date created:
# Date last modified:
#

In addition to the usual grading criteria, your program will be graded on your use of functions to divide the problem into manageable pieces.

Did you remember to

# Description Complete
1 Did this project by yourself? Yes or No
2 Name the file correctly? Yes or No
3 Put your program in a main function? Yes or No
4 Match your output to the sample output? Yes or No
5 Use meaningful variable names? Yes or No
6 Use comments to document your program? Yes or No
7 Include test cases? Yes or No
8 Be certain your file compiles properly? (If not, it is a 0!) Yes or No
9 Put the right header at the top? Yes or No

Try to use good variable names and keep your code as readable as possible along with a good Program Documentation. Coding style is part of the marking scheme.

Happy computing!

N.B: Next, you are going to make sure you can use the submission properly. This will be how you turn in your projects electronically. The submission procedure only accepts zip files (NOT rar Files), so you are going to create a “FinalProject_YourFirstName_YourStudentID.zip” file containing all the programs you just wrote as well as this document with your name and student number added to it. To create a “.zip” file, find the directory where the files are saved and select all of them. If you right-click on one of the selected files, you should have the option to create an archive by choosing “Send to” then “Compressed “zipped” Folder”. Rename the created “.zip” file and give it the name FinalProject_YourFirstName_YourStudentID.zip.

10 marks will be deducted if:

  1. the email did not have a full name and a student # in the subject field or
  2. the procedure for zipped file is not followed or
  3. Python template and documentation are missing or
  4. This document, with your name and student number on it, is not included with the zipped file
  5. screen shots of sample outputs are not included with the zipped file

A score of zero (0) will be given to every student whose email is empty.

Incomplete projects may be accepted for partial credit but no late work on this project will be accepted after Friday, Dec 7th at 11:59 pm