Assignment 5 Wiki - AustinSoup/CS101L GitHub Wiki
Check Digit
A check digit is a digit that is used in a string or value that determines if the rest of the value is correct. A formula applied to the rest of the values is applied and the value is compared against the check digit, if they are equal, then the number was likely valid. If they are not, then a character may have been entered incorrectly. Check digits are used in ISBN library book numbers, VIN numbers on your car, Credit Card Numbers and almost any place where data entry errors are likely to happen and must be avoided.
You will want to use functions to break the program down as much as possible into smaller tasks. While you are testing you may also want to show code word so that it is easier to test. We’ve again given you a set of unit tests to pass. We have not defined the functions in the solution, but will give you the function signatures that are required. You may add extra functions.
You should be able to iterate over strings by index, get a value in a string by index. You also need to be able to convert a string value to a number. All characters in a computer have a number associated with them. For instance, the string character A has a value of 65, while a lower case a has a value of 97. You can, get the integer value of a string character with the ord function. You can convert it back with the chr function as shown below.
Notice in the sample below, we can get the value of A, then we get the value of a, then we get the character associated with the integer 66. The last part, gets the integer value of the character for the upper case A, we add 1 to it, convert it back to a character with chr and then output the result. The character that is one higher than A which is B.
At the start of the program I changed all the def strings to library_card. Then I went through and started to finish off the strings for each of the def functions. When coding the functions, I had to make sure a string returned the correct string or the program would be inaccurate. Then when I correctly coded the strings, I made sure the print statements were correctly displaying the proper text. After all the coding was finished I tested out the program to make sure it ran.
The screenshot shows how the program runs. First it has the user input a library card number. If the number is not ten characters then it will ask the user to input again. Then if the library card is 10 characters but the first 5 characters are not a letter between A-Z. it will say the card is invalid. So once you enter a card that has 5 first characters between A-Z and then 5 numbers, the program will say the card is valid. It will also output what College the owner of the library card belongs too, Also it will output there student classification. However if a user inputs 10 characters that meets all requirements, the library card can still be invalid if digit 2 does not match calculated value 0.