Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help please in python a United States Postal Service uses a bar code encoding system called POSTNET to represent 5-digit ZIP codes. In this case,

help please in python
image text in transcribed
image text in transcribed
image text in transcribed
a United States Postal Service uses a bar code encoding system called POSTNET to represent 5-digit ZIP codes. In this case, each digit of the ZIP code plus the check digit are represented with a series of five full or half vertical bars. Each decimal digit is represented according to the values in the data file named postnet-encoding dat data file, which contains six columns of data on each row-See above The first column specifies the decimal digit to be encoded, and the remaining five columns specify the height of the bars that will represent that digit. For example, if you look at the row for decimal digit 8, we have 8 1 0 0 1 @which means 8 is to be encoded as 1 0 0 1 where a 1 indicates a full bar and a indicates half a bar. So, for example, ZIP code digit 8 would be represented as Iuli To represent 5-digit ZIP codes, one must do the following: 1. Add the individual digits of the provided ZIP code. For example, the sum of the digits of ZIP code 97341 is 24 2. Compute the remainder of this total when integer-divided by 10. For the total 24 the remainder from the division by 10 would be 4. 3. Subtract the value from STEP 2 from 10. The result will be your check digit. For our example, our check digit would be 10 - 4, which is 6 Finally , to generate the bar code, you will do the following 1. Generate a full bar to indicate the start of the bar code (1 bar total) 2. Add the 5 bar representation of each of the five digits of the ZIP code (5 x 5 = 25 more bars + 1 from STEP 1 = 26 bars) 3. Add the 5 bar representation of the check digit (26 bars so far - 5 more bars * 31 bars total) 4. Generate a full bar to indicate the end of the bar code (31 bars + 1 = 32 bars total) 11:10 PM 13 3. Add the S-bar representation of the check cigit (26 bars so far + 5 more bars = 31 baru total) 4. Generate a full bar to indicate the end of the bar code (31 bars + ++ 32 baru total) For example, the ZIP code 97342 will be represented by the 5 bar representation of digits. Therefore, with the addition at one til bar at the beginning and end, a POSTNET barcode will have 32 bars. Now write a Python function called postnet_barcode(zipcode, encoding foca". by which takes the ZIP cod as an integer, peode The encoding parameter will be a dictionary and its contents will be returned by a second function you need to write named read_postnet_encoding (See below). The full bar character defaults to the provided value of the foc parameter, and the half bar character defaults to the provided value of the he parameter. Your function must return a string with the POSTNET barcode of the given ZIP code. Finally, postnet_barcode() must raise an AssertionError when the ZIP code does not have tive digits exactly You will write a Python function called read_postnet_encoding(data_filepath) that will read the POSTNET encoding table from postnet- encoding.dat file and retum a dictionary that will map each of the ton ZIP code digits to a list of numeric 1's and Os, as specified in the encoding data, in the same left to right order For example, the value for ZIP digit should be represented as 8: (1, 0, 0, 1, 0); in the dictionary that read_postnet_encoding function will return See the test cases further below for more information This problem can be solved with 15-20 lines of Python code. PROVIDE YOUR ANSWER IN THE FOLLOWING CODE CELL In [ ]: def read_postnet_encoding( data_filepath); See specifications above H # YOUR CODE HERE pass def postnet_barcode( zipcode, encoding, fbc='1', hbc''); See specifications above # YOUR CODE HERE pass

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

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions