Question: 5.48 Programming Project 1: Checksum Validation Fixed-length numbers are commonly used for identification purposes; for example, think about bank account numbers and social security numbers.



5.48 Programming Project 1: Checksum Validation Fixed-length numbers are commonly used for identification purposes; for example, think about bank account numbers and social security numbers. Because they are so often typed in by humans, their use is sometimes error-prone. One historical way of automated validity checking of such numbers is to reserve one digit as the "check" digit, whose value is determined by a special "checksum" algorithm applied to the other digits. Part (a) in the figure below illustrates how a trailing check digit is calculated for the number 176248: it is the digit that when appended to the number in the ones place produces an augmented number whose checksum is divisible by 10. Here, the checksum algorithm involves doubling each digit whose index in the string version of the number is odd and adding the results together; in the case that doubling a digit produces a two-digit result, those digits are also added. Image credit: Some Drexel ECE faculty member, I guess. Part (b) demonstrates the validation procedure that just performs the checksum algorithm again on the augmented number. Note that it is assumed by the checksum algorithm that the trailing (or ones) digit is the check digit, so it is not doubled when added to the checksum. Note that if any one of the other digits is incorrect, the checksum fails. Thus, the check digit "3" in the ones position "validates" the number 176248 The code template below, my_checksum.py, partially defines a function do_checksum () with a single integer argument argument. The last digit of this argument is a check digit such that the checksum is expected to be divisible by 10. Your do_checksum () should return True if the number's checksum is divisible by 10, and False otherwise. The __main__ block is provided to allow you to test the program on your local computer. It does not matter what you put in the __main_ block; only your do_checksum() function will be tested. Check digit 6 2 4 8 3 14 16 1 + 1 + 4. + 6 + 4 + 4. + 6 27 + 3 = 30 (a) Computing the check digit. 1 7 6 2 4 00 3 1 4 1 6 1 + 1 + 4 + 6 + 4 + + 1 + 6 + 3 30 (b) Checksum validation. def do_checksum (N): passes_checksum = False Your solution goes here return passes_checksum if == name main ': a=728498251 # Instructor note: should not pass print('{:d} {:5} the checksum test.'.format(a, 'passes' if do_checksum (a) else 'does not pass')) a=728498254 # Instructor note: should pass print('{:d} {:5} the checksum test.'.format(a, 'passes' if do_checksum (a) else 'does not pass'))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
