 Hi, this is Christian. This is part two of the video on building this postal code application. Now, if you want to watch the first video, we'll explain how to solve this problem. You should watch that video first in episode one. But again, this program is really a really tiny Python program that will convert a five-digit zip code to a barcode representation that you see printed in most U.S. mailers right here. So the process is basically to grab each five digit numbers, convert to their postal code or barcode representation, print them out, calculate a check digit number by doing add-and-mode these numbers up and a multiple of 10. So track that from 10 to get your check digit and add that check digit as the last digit here. And you will enclose the entire six digits here with the open frame and frame bar and ending frame bar here. Okay, so we're going to refactor our code to print this program using a different method. So let's go to the IDE. It's over here. This is the program that we're going to convert. As you can see, when I enter a zip code number, it prints the barcode representation in this format. So we're going to copy this code, make a copy of it. So I'm going to do a Ctrl-C, Ctrl-V to paste it, and I'll just keep it as it's barcode one. That's fine. Open this copy. And then, so notice I'm going to do maybe just, I guess, three things in here to refactor this program. The first thing is, instead of having your, you know, coded this way, one, two, three, do nine, I'm going to do like this. You can represent this whole strings here as one long zip code. So that means I can combine this with this. So add them all up in this order to a strings. And let me expand this so we have more room. Just make sure they are in the right place in the right order. And remember, these are five digits. So they are like a multiple of five. Instead of zero, I'm going to rename this to say zip code all caps. Okay, I'll keep the rest as is. And so now we're going to refactor this function here. We'll get the digits. So instead of returning, you know, zero, one, two, three like this, we don't have that anymore, right? So what we're going to do is going to grab the five digits of code here, this five digit number. This five digit number here represents zero. The next five represents one and so on, right? This is one. And this is two and so forth. Right. So you have to know where to start. So the digit comes in, if it's a zero, we know that zero starts from the zero position all the way to the fourth position. Okay, if it's a one, then the one starts here at the fifth position to the ninth position, right? That's a two, so a 10. So you get a pattern here. So that means because these are multiple of fives, the starting point to grab the string is from the starting point of the multiple of fives. So that would be whatever this digit is, if you times by five, you're going to get the starting position of that number. Right. So if it's zero, five times zero, you start at the zero position, and then you grab the next five digit. If it's a one, five times one times one is five. So it starts at the fifth position, index five. And from here on, you grab the next five digit and so forth. Right. So but that means with that, you can go ahead and recreate or refactor this code to have a star position, say that it's going to be the digit, whatever the digit is, and we have to convert that to integer first. And we multiply that by five. So this is our starting point index. And then where, when do we stop? Well, we start by counting next the next five digits, right? So we can say stop is where where is at the start plus five. And that will be our ending position. So we just basically count count the next five digits. That's all we're doing. And then once we do that, then we will return that piece of string to wherever it was. So I'm going to remove all this. And to grab this piece of string in this range, you can do just return the zip code. And using the slicing operator here, here, starting at the start to the stop position, right, it's going to return those five digit representation here to wherever it's been, whatever this number is. Okay, so that's all we do. As you can see, we shorten the code to three lines instead of, you know, 10 or 12 lines. So that is a shortcut in a way. And then when we print the digit, so here we get the barcode. That's what this one does. Got a digit back. And so instead of going through each of those digits and converting to, you know, have, I mean, adding to the half bar to build this barcode, you can do this, you can remove all of that. And then here, we're going to do the following, right? Remember that strings have a replacement. You can replace all the characters. As you can see, the old character string or strings with the new characters. And you can count how many you want here. So it's basically, if you want to count replace all of them, you leave that blank, right? So the old string or all character is a one. As we find a one, we're going to replace that with the pipe symbol. That's the full bar. Okay. So I can copy this again, press the Ctrl Alt, down arrow. And we're going to replace all the zeros with the half bar. And there we go. So now we got our barcode. And then you just now just print it out. There we go, four lines of code. And I think that should, that should do it, right? So you can see we shortened these two functions to about half more than half the code. And also we move a lot of variables up here as well. Let me kind of fix this a little bit to make it nicer. Okay. So now let's give it a test. And let's run this. And I'm going to copy the same code here. Just make sure it matches that. Okay. Oops, I had a wrong, sorry. Copy that. And let's do one more time. Let's run it again. Okay, something is not right here. Okay, let's see what's going on. I think I need to cancel this out first. Okay, it's not doing, let's clear this thing. I messed up somehow. All right. So here we go. Let's save it and run it. Okay, so here's a zip code. I paste that by zip code. Okay, it doesn't work. Let's just go by four, three, two, one. And here so you can see, okay, I guess the one didn't work. But we did work and it didn't replace the half bar. So if you want, it didn't work. So let's see why. When we replace the zeros. Oh, yeah, because here I basically, you know, reassigned to the same barcode. And this is not right, right? When I first changed the code digit to the barcode, here it should have been the current code. So it should be the barcode and not the original one. So that's why it wasn't correct. Okay, let's try it again. Okay, so here we go. Five, four, three, two, one. And there it is. We can verify by checking the digits, right? You can also run against the code over here. The barcode is ascended this one. So nine, five, zero, one, four. Copy that. Let's go around again. And we'll run it. And let's run here. Okay, I'm going to copy this and match with our code in the document and to see if this is the same. As you can see, exactly same as before. So that's all we did, right? We basically changes to a long string of code numbers. Make sure we know what the number, how many digits we want, get the digit, multiply by five, because it's multiple of five. And then you just grab the next five from the, from the start to the start position, and we turn that piece of string. And then we just basically do a replacement, replace all the ones, all the zeros with that and we print it out. And that's it. So there you go. Have any questions? Please let me know. Thank you.