Question: in python with comments Excercise #3 Postal bar codes. For faster sorting of letters, the United States Postal Service encourages companies that send large volumes

 in python with comments Excercise #3 Postal bar codes. For faster

in python with comments

Excercise #3 Postal bar codes. For faster sorting of letters, the United States Postal Service encourages companies that send large volumes of mail to use a bar code denoting the zip code (see following Figure). The encoding scheme for a five-digit zip code is shown in the following Figure. There are full- height frame bars on each side. The five encoded digits are followed by a check digit, which is computed as follows: Add up all digits, and choose the check digit to make the sum a multiple of 10. For example, the zip code 95014 has a sum of 19, so the check digit is 1 to make the sum equal to 20. *************** ECRLOT ** C057 C057 CODE C671 RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CA 95014-5143 Frame bars Illlllllllllllllllllll Figure 10 A Postal Bar Code II.1.. ll. ll. ll lu .lll Digit 1 Digit 2 Digit 3 Digit 4 Digit 5 Check Digit Figure 11 Encoding for Five-Digit Bar Codes Each digit of the zip code, and the check digit, is encoded according to the table below, where 0 denotes a half bar and 1 a full bar: Digit Bar 1 (weight 7) Bar 2 (weight 4) Bar 3 (weight 2) Bar 4 (weight 1) Bar 5 (weight 0) 1 0 0 1 1 2 o 0 1 0 1 3 O 0 1 1 0 4 o 1 0 0 1 5 0 1 0 1 0 6 0 1 1 0 0 7 1 0 0 0 1 8 1 0 0 1 0 9 1 0 1 0 0 0 1 1 0 0 0 The digit can be computed easily from the bar code using the column weights 7, 4, 2, 1, 0. For example, 01100 is 0 x 7+ 1 x 4 + 1 x 2 + 0 x 1 + 0 x 0 = 6 The only exception is 0, which would yield 11 according to the weight formula. Write a program that asks the user for a zip code and prints the bar code. Use : for half bars, for full bars. For example, 95014 becomes 11:1:1:1:1:1::::::::::::11 Provide these functions: def printDigit(d) that prints the bars of one digit. def printBarCode(zipCode) that calls printDigit in a loop to print the full bar code. def main that reads the user input and make sure it composed of 5 digits then call printBarCode to display the bar code. hint: you don't need to convert the input to integer for both functions. Following are some sample runs Enter 5 digit zipcode kdklskd Wrong input Enter 5 digit zipcode 45791 1:1::1:1:1:1:::11:1:::::11:1::||| Enter 5 digit zipcode 1223 Wrong input Enter 5 digit zipcode 10826 1:::||||::::::::1:1:11::::||:||

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!