 Hello, this is Christian. Welcome to video three of the critical number check application. This time we're going to do a different approach by using two operators called the floor division and the modulus operator. And again, if you haven't watched video one, go back to the first video where I explain how to do this. Okay, so again, the total idea is basically do these two special operations here or calculations here. You're going to get two sums, add them up, you get a total at the bottom here at 50, and you check the last digit here. If it's a zero, then that's a valid number, otherwise it's an invalid number. And here are some numbers you can also check. All right, so let's go to the IDE. So here is the previous exercise. So I'm going to copy again just the first part here. All right, and we're going to add a new file. I'm just going to see C3.py. And we'll place it right in here. Okay, so let me close the right here. We can have some more spaces. All right, so this is the sum one again. And I'll use a with this time no conversions. The only conversion I will do is the very initial conversion here. When I read the number in, I want to convert it to an integer. That's the only conversion I'm going to do here. Okay, so the rest will be just all numbers. And by using the operators called the floor division and the modulus, you can see how powerful they are to solve this kind of problem. Okay, so here's the first one. Now I'm going to use a while loop in this example is just simpler. So the first thing you want to do is once you get the number, then you want to check if something is true, right? And each time we want to go through the the loop here, I'm going to decrease my number here, I'm going to drop one number or two numbers at a time. That is the idea. So say I have a gap, I got my first number here, this is the first group of numbers. So what I do is I'm going to grab the last digit, right? Right, grab the last digit, add it to the sum. And you move to the next, you skip one digit, go to the next one digit, add it to the sum. You keep adding that until you reach the end of the zero. So every time I want to add the digit, I truncate the last digit, right? I remove that out of the list. Watch every move two of those lists, right? You move those two out. And then you grab this after the sum, remove them out, add this one, remove, add, remove. Eventually, you can see it again, you're going to get zero. So when the length or what the number of the temp is zero, there's no more number left, then you can stop, okay? So that is the idea here. And let me put these numbers back. So what you do is you can say while a temp is not equal to zero, right? Because right now, these are indeed numbers. So when it's not going to zero, then you can say something like this. And you check this first digit here, you want to grab that first digit and the far right, and then add it to the sum. So how do you do that? Okay. And so you could, you would just say, you could do something like very simple. So the sum one plus equal the last digit. So how do you get this last digit? All right. Remember, these are base 10 numbers. So let me put, let me show this again, on the terminal here, so you can kind of see what it looks like. So remember, if I have a number of, you know, one, two, three, if you want to grab the last digit, you would do a modulus 10, right? As you can see, because this is a base 10 numbers, right? And a base 10 digit. So you grab the last digit. So I grabbed the last digit. And that's what I want to do. I'm going to grab the last digit and add that digit to the sum. So exactly what I'm going to do here. So we say temp modulus 10. And that will give you give you the last number you added to the sum. And then now I have to update my temp variable, right? So now how do you remove this digit? If you want to remove just a single digit, you would do one, two, three. And then this is the floor division by 10. If you do that, you see that one digit is has been truncated, right? It's been removed. So I only have this much left. But for our exercise, we're removing two digits, not one. So I grabbed this last one, used for my calculation. And I'm going to truncate two numbers instead. So you could do it two times if you want, right? You could say one, two, three, 10. And then you do it again, you get it the second digit, or you just do a division by 100. And that will give you indeed that just the last digit left, right? You truncated two digits, you get the last digit. Okay? So let me do a little bit more like one, two, three, four. If you do 100, you see that I dropped the last two. Now I have this digit left. So now I need to grab this digit again. So again, back to the modules operator. So you can see that process here back to my operators. So here, I would say my temp is equal assigned to the temp itself, right? Floor division of 100. And oops, not that one. And that will solve the problem. Okay? Now notice if I do this, then my second, a while won't work. So I'm going to, I'm going to rename my variable here to something else. I'll call this card. And then I'll do a temp is equal car here. Okay? Because I want to be used again down here for the other sum. So that's my sum one, as you can see, no conversion. But the sum two, this is the other part, right? Where you, you know, we add each, each single digit together and you add it to the sum two. Okay? And so I'm going to do something similar. So while temp is also not equal to zero, then we do the following. Now, how do we do this? Kind of similar, right? So first, what do we do? We grab the second digit from the right. So how do you do that? Hmm, right? You could do, you know, floor division by one. And you grab that using the modulus. And if floor division by one or by two, you grab that, right? You keep doing that way. I mean, lots of ways to do it. But I want to do it this way. So first thing is, I'm going to remove this group. Right? I'll grab those two numbers. And then, right, and then you will grab the a ninth digit. Okay. So for example, if I have like one, two, three, four, I want to grab the last two digit, which is 34. So I would do a mod of 100. Right? That will give me 34. Okay. So once I got 34. Now, how do I grab the number three only because I don't want to get the last digit, I just want, oops, I just want the first digit. How do you do that? Well, that is back to this again. So 34. If you do a floor division of 10, not 100, right? 10 is a single digit. I'm going to get a three. So there it is. I got my three, right? So that means I got my nine. And what's the next step says? It tells me that I have to double it. And I can double that, get a six. And they I can, you know, add that as well to the sum. All right. So that's is the first thing I'm going to do here. So I want to say n is temp. Okay, I'm going to do a mod of 100. That will grab, I'm not sure what is keep writing error arithmetic here. It's going to grab the last two digits. So again, here, if it's 80, it's going to grab eight and zero together. I got that did that pair of numbers. And then I'm going to grab just the letter of the number eight out of that. So you can do it again. And is equal to n floor division 10. Okay, so now I have that digit only. And then finally, I'm going to multiply that by two, right? And now I got my sum of those of that single digit. If it's eight, it's going to be 16. If it's a two or three, it's going to be a four or six. Okay, so whatever the digit is, you're going to get that total here. And then we're going to split those digits and add them up. Right? So if it's a, it's a nine, that's going to be 18. 18, that's a one and eight. So I'm going to plus that number. So again, if it's a number like six plus six is 12, how do I get each of those numbers? I just showed you, right? The mod will give you a two, right? And the floor division give you a one. So there it is, I split my numbers, and then I will add them up. Right? That's what I'm going to do here. So my sum two, it's going to be equal to the n, right? That gives me my first digit. That's the first digit plus my second digit, which is the two. And I got my sum there. So in this case, I don't have to worry about a single digit or a double digit or not. It'll always work. I don't need to check it because I'm not concerning about the index position. This, however, you have to check because if it's a single digit, this is going to be a problem, right? But using these operators, it'll always work. It's going to give you a zero anyway, if there's none. And then once you do that, you get your sum. And finally, you have to update your temp just like here, right? You have to drop the last two digits. So again, it'll be the same as above. There we go. And I should have my new temp and it goes back and then the whole process starts again. And then finally down here, we're going to verify. So again, it would be a total equals sum one plus sum two. Again, no conversion here. And then we need to check the last digit, right? If it's a 30, how do you check the last digit? Same as this, right? So you could do something like val valid value equals total, okay, a mod 10. That will always give you the last digit of your numbers, like we did here, give you the last digit of the whole number. Now we get our valid value, and then we just check it. So if valid value is indeed equal to zero, then valid, otherwise invalid. So I believe that may be it. Let's give it a test. Clear my console over here. And let's give it a run. So let's go and copy one of these numbers, the first one here. So, okay, it's there's an error in here. Okay, so that's not correct. I think let's try a different one here. I may have a typo or an error somewhere in my calculation. Okay, that's that's valid. Unless I changed the number for some reason, let's try a different number. Yeah, those are valid. Okay, so there's an error in my code somewhere. So let's figure out why because my total is is not correct, right? Okay, so let's run the first one again. Because the first one shows us some results, we can check why. This is supposed to be a valid number. Right, so the first sum is 23. As you can see, sum two, we got a zero. So I think I did something wrong here. And you know why? I did not catch that, but because our temp has been set to zero, right, once we did the while loop, I forgot to reset my temp to a different, to a vector number. So I have to do temp is equal to card again. Which is why I wanted to preserve my original number here. And I forgot to do that here. Okay, so that was a tricky one. So that is what's called a logic error, as you can see. Because I know my code looks pretty correct. So let's try again. All right, and I'm going to paste in the number again. And so here we go, we got 50 for that one. That's correct. Let's try this one here. And that is indeed valid. And we'll try one more the last one here. And we should be good to go. So here we go. That's all working correctly, beautifully. So you can see how I did this using these operators. And I'll show you one way how you can refactor this code is confusing. But if you're interested, of course, you can always do that. So every time we see something like this, like temp equal temp something, right, and equal and plus something, multiply something like this, you can rewrite this to make it a little bit short by removing the temp here, right, and put the put the signs over here like that, right. So here we go. And here we in slash slash 10. And in star two, right. And then this part is fine as is. But this part here will be again slash slash 100. Okay, so just another way to make your code a little bit shorter. It could be a little bit confusing, but it does, you know, reduce some bytes. So it makes a little bit shorter. And if you run it now, it should still work. So you go and as as it is you see here. Okay, so if you have any questions, please let me know.