 Hey, yeah, and welcome back to our from scratch to Python series. This is the second video where we're going to locate the call and position of a line of text here. If you haven't checked out the first tutorial to create these lines of text, then go check out the video in the top right-hand corner right now. And I might even have a starter project for you down in the description before you go and s us out now on the surfing scratcher. And I'm here to help curious learners just like you along on your learning journey. So let's get stuck into it in just a sec. OK, so I like to put things down in a comment just to have a bit of a plan of what we're trying to do here. So the first thing that we need to do is find the location of the colon in the line. So in a line of text, we need to figure out what number the colon value is for each line here. And when we know that, when we know the composition, we can split a line into both a word and a sentence. So that's why we're using the colon there. And then we can create some helper functions just to clean it up and look really nice. So this is going to be using a lot of control blocks, a lot of variables, and we're using some lists as well. I'm also going to be using some my blocks. The reason we're using all of those is because when we jump over into Python, it's going to make sense. Python uses these a lot and most other programming languages that are just built on these things. So that's why this is such a neat little project to help you transition. OK, so let's focus on the first part here. And we're going to find the location of the colon in the line. The first thing I'm going to do is create a new variable or just rename this one or just rename this one, because I'm not going to use my variable. And I'm going to call this colon position. And I'm just going to use some camel case here. So we've got a new variable. We're going to set the colon position to zero. So that means basically we're setting the colon position to the start of a line of text. That's what this code block is going to refer to. OK, so what we're going to do is we're going to loop over each character in this line of text and check to see if it is a colon character. OK, and each time that we're looping, so we're going to check the first character, second, third, fourth, up until we get to the colon. And we're going to keep track of that. In Scratch, that's a little bit cumbersome, but we're going to go through the painstaking process and you'll see down the track in Python, it is an absolute breeze to do that. So let's create another variable that's going to be called a sort of a counter variable. And the best practice is to make a counter variable named I. I'm actually going to call it underscore I just to show that it's going to be something that I'm going to reuse throughout this project in multiple counter or iterations that we're going to be making here. So here is my I variable going to click OK. And you can see how I variable has now come up on the stage here. I'm also going to put the colon position there so we can just check out what these values are doing. Again, we're going to connect these and we're going to set it to zero as well. Where I is just going to stand for index and the index is just the current value that we're looping through of the particular character in this line. Now, if you're watching this as an educator or a student in a class, I recommend maybe assigning one of these values to one student and assign the other variable to the other student because what we can do is we can go through line by line to try and understand what it means. And if one person is thinking about one variable and the other person is thinking about the other variable, I'm not having to think about them both simultaneously. So it just helps us sort of act out what's going on. And I found that works really well with the students that I've taught with this project. OK, let's create this loop. OK, so I just grabbed out a repeat until block and we need to create a Boolean condition here. We're going to repeat until a value is greater than zero. And we're going to repeat until the column position is greater than zero because we set column position to zero here. So this will just infinitely loop until the value of column position is greater than zero. OK, so we need to put in some logic inside of this loop. There are two things that we need to do. We need to increment the value of I. So that's pretty easy. We can just change that value by one. And if we click this code block here, you'll see the value of I just tick on forever. And it is getting very large very quickly. So let's just set our variable back to zero there. And then what we can do is we can check to see what the character or the letter is at the position of I. So if we jump into our operator blocks, we can get this nifty little block, which is the letter number of the word that we're interested in. So let's just break this down in case you're not too familiar with it. So the word that we're interested in is this whole line of text here. So just for testing purposes, I'm just going to copy and paste that first line into here. And the letter one of this whole slab of text here should be D. If I click this, you'll see that it is D. Then if I go ahead and I get the variable of I to replace that hard coded number there and I click this, you'll see that currently letter, you'll see that the value of I is equal to zero. So this isn't equal to anything at the moment. But if we change the value of I to one, and I've just done that over here in the code pane, we click I, so it's now equal to one. And you can see that the value or the letter of I, which in this case is one is equal to D. So I hope that's a little bit clear for you with what is going on there. And each time we loop through this, we're going to increase the value of I so then we can check each individual letter of this whole slab of text here. And that's where if one of you is the column position value and one of you is the I value and you're talking your way through this each time this iteration or this loop happens, you can visually see what is going on here. So now we've got a piece of code here that is going to check each individual letter of this letter of text. We want to check to see if it's equal to a colon. So let's go out and get an equals boolean operator block. And let's just type in the colon symbol there. And I'm going to click and drag this text inside that boolean block. And now we can see that we are looping through to see to check if the current position of this particular subtext is equal to the colon position. Now, whenever we have a boolean condition, we probably want to wrap that inside an if block sandwich. So let's put that condition inside there and we connect it to beneath the changing of the I variable block there. So currently, if you read through this, you'd go, OK, we're going to set the colon position to zero. So let's say that's Mike and we're going to set I to zero. So then maybe that's Amy and then we're going to repeat until the colon position, which would be Mike is greater than zero. So the first thing we do is like, hey, Amy, change your value by one. So Amy, what's your value now? Well, your value would be one because you were at zero. So if the letter position of I, which is Amy, hey, Amy, what value are you? Well, I'm one. Well, we'll check out what D is there and that would be D. So is D equal to the colon character? No, D is not equal to the colon character. So we'll go back to the start and we'll try it again. We're going to change Amy's value by one because she's equal to I here. And now Amy's value would be two. And then we're going to inspect the A here and A is still not equal to the colon. And we keep going until we equal the colon character. Do you know what we're going to do when we hit that condition? Well, this is where Mike gets a little bit excited because we can set the colon position to the value that Amy is currently at. So we can set the colon position to the current value of I. And that is how we can find the value of the colon position. So for this particular piece of text, we've got one, two, three, four, five. So the composition is number five of this type of text. So if I click and execute this piece of code, we'll see I tick up to five and the composition should also set to five. So let's check it out. Boom. And that has happened there. If you want to, again, see this visually happening in action, what you can do is just put in a weight block here and you can wait a second just to see this value to go. I'm just going to put in 0.5 seconds just to speed it up a little bit. And now watch the values of I and colon position change over here on the stage. So I'm going to click the block, but I one, two, three, four, five and colon position has now been set to five. If you want to test this is working, then you could get a longer word here and put that in as your test piece of text. And you can click this code block. You can see we're counting up until we reach the colon position, which is a little bit longer for the word slippery. It is in a position nine. OK, we're just about done with this tutorial. We just need to do a couple of cleanup things that we're going to use my blocks for. So currently we've hard coded in this piece of code for this particular line. But that's no good because we need to check every single line. So we need to make this some kind of template. And the way that we're going to do that is using a my block. So let's create a my block. And I'm going to call this my block set colon position in line. I'm just going to put the colon there and we're going to add an input and we're going to write what we're going to pass to it. So I'll break down what that is all going to mean. OK, so here's our my block. Let's just connect all that up. I like to name our my block. I like to name it after what it actually does. And this code block, it just sets the colon position in a particular line. And we're going to pass it a line. So what I can do instead of hard coding this line in here, we can just grab this parameter and we can stick it in there as like a template. So now whatever line we feed this, it will check to see where the colon position is. And I can test that by just dragging out this block. And let's get one of these lines of text to create that a little bit bigger. Let's get another one of these lines of text. Let's copy it and put it inside this custom block. And let's see our colon position and I change. Cool. And it is also a position five. I'm also going to get rid of that way block because I'm done testing. So we've got a nice contained piece of code here that is going to identify or locate the colon position of any piece of line or any piece of text that we pass it. And this is really neat. And we're going to use this inside of other blocks now. So let's park this tutorial here. We're able to locate the colon position of our lines. In the next tutorial, we're going to look at slicing up this line of text into both a word and a sentence. I look forward to catching you in that one.