 So in this video, I'm going to do what I like to call a code along I'm going to more or less solve a problem and I encourage you to code along with me as I'm going through the process Just so you can see sort of this is how my mind is working when I try and solve a problem So in this case, I'm going to just solve something from coding that I love. I love this website I use it as inspiration for some of my problems in Classes I've taught in the past, but okay. Well Given some non negative number return true if that number is within two digits of some multiple of ten Okay, and it gives me some examples, but to walk through this Just a few different times so we can see that so if we're thinking about something like 12, right? 12 is within two digits one Two of ten because ten is a multiple of ten. So that's a true statement something like 15 is not going to be because as you can see if I were to write out all those numbers up to get to ten 15 14 2 Sorry 1 2 3 4 5 so it's not within two digits of Ten, but this also expands out into larger numbers 72 Well again, what is a multiple of ten that would be close to 72? It would be 70 So one two That's a true statement Okay. All right, so we've got an idea of what we're looking at here We need to be within this Threshold of ten so When I think about that how I'm going to go about doing this is I need to Extract out that remainder so just as that refresher. We're going to work off of the modulo Again that modulo or modulus that matter. It's You hear both of them. It is going to produce our remainder and the idea is if I did something like 72 divided by 10 that could be evaluated Like this in the long division style where oh well It skips over this first one and then it can go into 10 can go into 72 seven times We would get a remainder of two So again, that's sort of where we're going with this is that we're producing out that too Then you know if we I'll just call this r for our sake now. I can do an evaluation If that r is less than or equal to two True Elds false Okay, so we've got a good idea of how we want to We've wrapped our head around the math of what this question is asking. Let's actually go about Solving it So to speak so the first thing I'm going to do is I am going to just copy This text from this website over into my own little Block of code on Jupiter. This is just going to be so I can have easy reading I am going to add one more to this since we've been working off of that 72 And I don't know the special key for that arrow. So I'll just naturally do it like that So now that we're kind of working off of that. We see a few different examples I'll make one more just for our sake 74 All right, well, this is going to error out if I try and run it because it's not code So I'm going to highlight everything hold down control and hit the slash key That's gonna make everything a comment And then I'm just going to do some little bit of fiddling with the text So I can do that quite easily there Okay, so we've established we've got our problem So the next thing I'm going to do is I'm going to ignore the function process part of this I'm not going to worry about that because Again, I'm wanting to make sure that I've got my logic correct before Expanding out on it. So the first thing I need to do is establish a num And we'll work off of that 12 to start so to speak and So the next thing I need to do is again, I need to get my remainder So remainder is going to equal num modulo 10 Okay, so we've got that first part taken care of Then the next aspect that we need to work off of is we need to make our evaluation if remainder is Less than or equal to two Print we'll just say Yes for now else print No And there we go. Okay, I've ran it. I tested it awesome fantastic We throw it on that 72 works 74. We should see a no Awesome now. It's time to convert this into a function So simple very easy kind of approach to this I'll start with building out that functions near 10 with num. I No longer need this first value of num equal 74 because that is going to be passed to me via the num Parameter so I can get rid of this and Then I'm just going to highlight everything and hit tab That's going to push everything into my function and we can work from there So now I am going to get rid of these print statements because I'm Specifically at least to the problem. It says to return true if the num is within two So we need to sort of adhere to the rules of the problem. So in this case Return true return Okay, so I'll just kind of do a very quick check on this real fast True awesome that I've made a call to it using 12 in Jupiter will magically do this for me now the next thing I'm going to do is I'm going to take these little test cases and Just move them down and more specifically I'm going to use these as my test bed to see if everything works So again, they're all comments right now, but I can highlight them control slash again They're no longer comments But they are you know, I still need to make them a string in this case Manually and I am going to modify and just tweak these just ever so slightly So I want to say that this is my expected and I'll just highlight and Put that everywhere and then I will also have an actual section that we'll get into in just a second So actual actual that should be false Oh Actual actual and good thing. I caught it up, but now I'll come in and Let's see comma, comma, comma, comma, comma chameleon That was for me. That was not for you sometimes you you know You just kind of you need to have a little something going on in your head while you're you're coding 22 and 74 the last little thing I will do is Add in a print command at the front There we go. So what I've just done all of this coding is this first Section or rather, I'll just start here. This first section tells me what function. I am actually calling and More specifically printing it out so that I can do a comparison and know which one maybe screws up Then I have what I expect the value to be And luckily coding that had some and then I did to for myself 72 and 74 that we worked out in little whiteboard and Then I have a section specifically for the actual result even though I think it should be true or false or true or true or false That may not always be the case, right? I may have coded something incorrectly But we confirm that by saying shift enter and we see true with true false with false true with Okay Okay. Oh, okay. Oh Okay So where we're going on with this part is Specifically we've only been doing things that are ahead of 10. We never did anything that was behind 10 so if we're sort of thinking about this in here So if we're looking at 19 modulo 10 that's gonna produce a nine and If we were looking at an 18 because that's still technically correct That's gonna produce an eight so we need something that is Less than or equal to two or Or Greater than and equal to eight Okay. Okay. So this is a compound conditional statement this can be true or this can be true and so to Expand on that that's wrong window So if we came in so if remainder is less than or or equal to two or Remainder is greater than or equal to eight Reload this in the memory rerun this There we go. Okay, so true we get a true false We get a false true. We get a true true. We get a true false. We get a false Okay, and that is one of the reasons why you do multiple tests because you do want to confirm and check each one of these You could have done this a few other ways as well just to show them off so This if statement right I don't technically need to make this an if with returns since we're dealing with Boolean values I could have actually Done return remainder this or that because remember what this sort of configuration is going to evaluate out to is a value if Remainder is less than two or remainder is greater than or equal to eight that by itself is going to produce a value Just as a little example here. So let me copy that Not all of it Just to show this as an example for a second. Let's imagine that remainder is six, right? Well, then the question is this print statement of What is the value of this conditional statement so remainder six that's Not less than two and it's not greater than eight. So that should be a false statement And it is in fact a false statement or in this case. We have a one That's a true statement. So I'm just getting to my point what we could have done rather than doing if statements since we're dealing with evaluations You could have also done a return And this would evaluate out into that same value Without having to be explicitly the ifs and elses. So again running through and there you have it