Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need code. Have provided all the instructions. Thanks. Check Digit A check digit is a digit that is used in a string or value that

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedNeed code. Have provided all the instructions. Thanks.

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. Python 3.7.1 Shell File Edit Shell Debug Options Window Help Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018 )] on win32 Type "help","copyright", "credits" or "lice >>> ord ("A") 65 >>> ord ("a") 97 >>> chr(66) 'B' >>> value = ord ("A") >>> value = value + 1 >>> ch = chr(value) >>> print (ch) B >>> | In our program, we need to associate a character with a numeric value to use in calculating our check digit_In our solution an A is worth 0, a B is worth 1, ... and a Z is 25_( We will only be using A-Z and 0-9. If ord returns 65 for an A, then how would we convert it to be a 0? Another way to get a value for a character is to import the string module_The string module has an attribute with all the upper case letters. Since, it is a string, you can use index or find to get the index of a particular character_View the sample below | >>> import string >>> string.ascii_uppercase.index ("A") 0 >>> string.ascii_uppercase. index ("B") 1 >>> string.ascii_uppercase.index ("Z") 25 >>> | Either of these would work well in our final solution. Check Digit Program The Linda Hall library wants to come up with a new library card numbering system for students_ The card number's first 5 characters are A-Z, which will normally be the first five characters of the student's name_The next character at index 5 is a string value either 1, 2, or 3 which represents the different schools; SCE, School of Law, or College of arts and Sciences_The character at index 6 is either 1, 2, 3, or 4. These are the grade levels; Freshman, Sophomore, Junior, and Senior_The next 2 characters are 0-9, and the last character at index 9 is the check digit to verify the previous values_The last character is also 0-9. CS101L UMKC School of Computing and Engineering The formula is the sum of all the values at indexes from 0-8_The value at each position is the value of the character multiplied by the index+1_We take the modulus of the final value and 10 to get the check digit value_Below is an example with the string ABCDE12345 index 0 1 2 3 4 5 example A B C D E 1 value 0 1 2 3 4 1 (index+1)*value1* 02*13*24*3 5*4 6*1 6 7 8 2 3 4 2 3 4 7*28* 39*4 9 5 5 1* 0 + 2 * 1 + 3 * 2 + 4* 3 + 5 * 4 + 6*1 + 7 * 2 + 8 +3 +9*4 = 120 120 % 10 = 0 The check digit should be 0._Since this check digit doesn't match the 5 in index 9 it would be an invalid number. Validations When a user enters a number, the final item evaluated is the check digit, but we can validate several things before the check digit_ Length of the card # value is 10 characters First 5 characters can only be A-Z The 6th character (at index 5) can only be 1, 2 or 3. The 7th character (at index 6) can only be 1, 2, 3, or 4. The 8th, 9th, and 10th character (index 7, 8, and 9) can only be [0-9] o Functions to Implement The following functions must be present as defined, and used in the program as intended. getuschgel function should take a string as a parameter and return a string based on what school the library card is used for. Index 5 value Returns 1 School of Computing and Engineering SCE 2 School of Law 3 College of Arts and Sciences Any other value Invalid School get.grade function should take the library card as a string parameter and return a string indicating what grade of the student. Index 6 Value Returns 1 Freshman 2 Sophomore 3 Junior 4 Senior Invalid Grade || character..value function takes a single character as a string parameter and return an integer representation of that value_A returns 0, B returns 1, Z returns 25. get check digit function should take the library card as a string parameter and return an integer with the value of the check digit_Using the formula and method above, here are some values for input and responses. >>> get_check_digit ("ABCDE1234X") 0 >>> get_check_digit("Zzzzz1259X") 6 >>> get_check_digit("VWXYZ 3459X") 2 >>>| verify.check digit function takes a library card number as a string and returns a tuple (2 values) a boolean and a if the library card is valid then it Error Returns Input string is not length 10 False, "The length of the number given must be 10" One of the first 5 characters False, "The first 5 characters must be A-Z, the invalid is not [A-Z]_A character % in character is at 3 is %" index 3 is shown. One of the characters from False, "The last 3 characters must be 0-9, the invalid idx 7-9 is not [0-9]_An X in character is at 7 is X" index 7 is shown Character at index 5 is not a False "The sixth character must be 1 2 or 3" 1, 2 or 3 Character at index 6 is not a False, "The seventh character must be 1 2 3 or 4" 1, 2, 3, or 4 The check digit at index 9 is False, "Check Digit 8 does not match calculated value 2." not correct_Example given is check digit 8 in string does not equal the calculated check digit of 2. The library card is valid and True, check digit matches Unit Tests You can run the unit tests against your work to check the functionality_It may not mean it's completely correct, but will help you in finding common errors. The unit test file is a menu, so you can test each function that you write separately_Each passing test is worth 1 point a piece_ The functions character, value, get..school and get grade should be the easiest to begin with. CHOOSE TEST TO RUN 1. Test function character value 2. Test function check_digit 3. Test function verify_check_digit 4. Test function get_school 5. Test function get_grade A. Test All 2. Quit ==> 1 Ran 3 tests in 0.004s OK CHOOSE TEST TO RUN 1. Test function character_value 2. Test function check_digit 3. Test function verify_check_digit 4. Test function get_school 5. Test function get grade A. Test All Q. Quit ==> a Ran 31 tests in 0.045s OK Linda Hall Library Card Check Enter Libary Card. Hit Enter to Exit ==> XY292 Libary card is invalid. The length of the number given must be 10 Enter Libary Card. Hit Enter to Exit ==> 1111111111 Libary card is invalid. The first 5 characters must be A-Z, the invalid character is at 0 is 1 Enter Libary Card. Hit Enter to Exit ==> VWXYZ 34592 Library card is valid. The card belongs to a student in College of Arts and Sciences The card belongs to a Senior Enter Libary Card. Hit Enter to Exit ==> BINGH14592 Libary card is invalid. Check Digit 2 does not match calculated value 0. Enter Libary Card. Hit Enter to Exit ==> BINGH14590 Library card is valid. The card belongs to a student in School of Computing and Engineering SCE The card belongs to a Senior Enter Libary Card. Hit Enter to Exit ==>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions