Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The encoding scheme for a five-digit zip code is shown in the above figure. The five zipcode digits are encoded using five clusters of bars,

The encoding scheme for a five-digit zip code is shown in the above figure. The five zipcode digits are encoded using five clusters of bars, where each bar is one of two heights: short or tall. The five encoded digits are followed by a check digit, which is computed as follows:

Add up all the digits in the zipcode to make the sum Z

Choose the check digit C so that Z +C is a multiple of 10 For example, the zipcode 95014 has a sum of Z = 9 + 5 + 0 + 1 + 4 = 19, so the check digit C is 1 to make the total sum Z + C equal to 20, which is a multiple of 10. Each digit of the zipcode, as well as the check digit, is individually encoded according to the table below, where 0 denotes a short bar and 1 a tall bar: image text in transcribed

Decoding from the bar pattern to the original digit can be easily computed using the column weights 7, 4, 2, 1, and 0. For example, 01100 (short, tall, tall, short, short) decodes to:

07+14+12+01+00=6 Unfortunately, the digit 0 is an exception. If you apply the same decoding algorithm for 0, you end up with:

1 7 + 1 4 + 0 2 + 0 1 + 0 0 = 11

So, bar clusters that decode to 11 will require special handling since the true decoded value is actually 0.

Write a program using PYTHON that asks the user for a zip code and prints the bar code. Use ! for tall bars and . for short bars. For example, if the user entered 95014, your program should produce:

 !!.!.. .!.!. !!... ...!! .!..! ...!!! 

Notice how there is an extra tall bar at the start and another at the end. These are called the frame bars and they are used to determine where the code starts and stops. You will need to implement the following two functions:

printDigit(digit)

printBarCode(zip code)

which you will use to implement the encoding algorithm. printDigit() should accept a single parameter (representing a digit between 0 and 9) and produce a single cluster of bars. The printBarCode() function should accept a single parameter representing a full 5 digit zipcode and produce a full bar code of 5+1 clusters with frame bars. Each cluster should be crafted using printDigit().

DigitBar 1 Bar 2 (weight 4) Bar 3 (weight 2) Bar 4 (weight 1) Bar 5 (weight 0) (weight 7) 0 0 DigitBar 1 Bar 2 (weight 4) Bar 3 (weight 2) Bar 4 (weight 1) Bar 5 (weight 0) (weight 7) 0 0

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books