 In this tutorial, we're going to be implementing the game part of our spelling game, where we're going to cycle through each of our words, say them, say the sentence that they're in, ask the user to spell the word, and we're going to check the result. It's a lot to get through, so let's get stuck into it. Hey crew, it's the Serping Scratcher here, teacher, server programmer, and on this channel I help curious learners just like you along on your learning journeys. Welcome back to our From Scratch the Python series, where we are trying to transition you from scratch to a text-based programming language called Python. We've made a game of scratch, and we're pretty much finishing it up in Python. We're translating it across. We've got a few more things to implement. If you're just jumping into this tutorial, go check the card in the top right hand corner right now, or a link to the startup project down in the description to follow along. First up, we're going to go through and implement all of these custom blocks here, and then we'll come back to this when the green flag is clicked block to implement it in Python. So let's go check out the say word block. So here we see the say word custom block, and we say a word, then we speak it, and we're going to wait a second. So in this tutorial, we're just going to print the word to the screen, and we're going to implement the text-to-speak engine in future videos. So over here in Python, we need to create the corresponding function, and simply all we need to do is print whatever that word is to the screen. The only difference is that we're going to pass a word in to say word, and we will print that word just like that. Over here in Scratch, we've got a wait one second block. In order to do that in Python, we're going to reference the time module, and we're going to say sleep, and we're going to sleep for one second. Now, see I've got a red squiggly line here. I need to go and import the time module. So I'm going to scroll all the way to the top, and you can see up here, when I've been referencing pre-print that I had to import it, and we need to do the same thing with time. These import statements are a little bit like the extensions in Scratch. So if I open up the extensions, we've got the music extension, the pen extension. We can't use these until we import them into our Scratch project, and it's very similar to the time and pre-print. There's so many different modules out there that other people have written that you can use by just importing them, and you get it for free. Pretty neat. Okay, let's scroll back down to say word. Okay, so let's run our project, and let's just test that function. We're going to pass in a string value, and let's just say hi. And then we go, we've got some text printed to the console, hi. So that is working as we want it to. We're going to do a similar definition for the sentence. So I'm just going to copy all of that, and instead of word, we're going to have sentence, sentence is the parameter, and we'll have sentence, and we'll print the sentence to the console. We're going to sleep for five seconds here, because we need a little bit more time to read the sentence. Now, you might notice a little bit of duplication going on here, and you might ask the question, hey, could we just use one function for both of these? And the answer that would be, yeah, sure, why not? You could just generalize it. You could make this a say function, and say the sentence that you want, and that would actually work for both of them. You'd need to add another parameter, so you could change the value of sleep here. But definitely, you could go ahead and do that if you wanted to. Okay, things are going pretty well so far. Let's implement ask user to spell word. So I've just written it down here, and it's going to take a word. Now, there's a special function, built-in function, that we can use to request user input in the console. And the function for that is just called input, all right? And if we pass in a string to that input, it will come up with a prompt. And the text that we're going to pass it is, spell the word you heard. Now, this will also return the input that the user enters into the console. So we're actually just going to return that exact value. You might notice that, hey, is it a little bit overkill to be using a function to just call a different function? And yeah, you're probably on the right track there as well. You might notice as well that we're feeding it a word, but we're not actually using it. And we will come back to this down the track because we want to actually use this for the text to speak engine. So we don't have it in there just yet. So that's why we will be using this function. Okay, I've just pressed the green run button. I've just pasted in the function name, and we're going to press enter. And you can see here, the console has asked us to spell the word. We can put in any text here and click enter, and you'll see that that becomes our return value. And so what we can do with this is we could create a variable here and assign that variable to the result of our asking the user to spell the word. So if I do that and we go, hello, and we check out what our attempt is now, we can see that attempt is equal to hello, whatever that attempt was for the user. Okay, let's just give ourselves a little comment here and a reminder to implement the text to speech engine because we need to do that for our word here. And we'll also need to do that in our sentence and our say word functions. Okay, next up is our check result function. You'll see over here in scratch in our check result, we've got our answer that we get from our ask input, which is up here, ask and wait. And we're also checking it against the current word. So we're going to pass those to as parameters. We're going to pass in our answer and also the word that we're trying to spell. Now the order of these don't matter. The spelling of them doesn't matter anyway because remember I said attempt up here and we use attempt in the console. If you wanted to make that attempt, it would be fine as well. But just for consistency with scratch, we'll use answer. And we've got an if and else block here and we can do something similar in Python. But the way we'll do it in Python is to set up a local variable and we're just going to assign to it a number and the number will be zero. Zero means no, it's the same as false. And we can say that if the answer is equal to the word, well, then we can just set result to one. And notice again, the two different equal signs going on here. We've got the assignment and then we've also got the comparison and I'm using this comparison to check two strings. Let's just jump down in the console to check that in action. So I've got the string here AB and let's check to see if AB is equal to AB. And that is true. So see how we can compare two strings to see if they're the same. Let's change the B to A capital B. And now it's false. So this is case sensitive. Now I'm going to do something quite sneaky. I'm going to put a dot lower here on the end of the AB. And what this will do is it will transform this string to all lowercase letters. I'll hit enter and you can see it's resulted to true again. That's because it converted this uppercase B into a lowercase B. So back off here, it's going to be important to put that lower in there so we can compare whatever input the user gave us to the word and we don't really care about the case because we just care about the spell. Okay, the last thing we want to do is return that result. So then we can click and run our project. We can type our function, check result. And we can put in two identical strings. And you'll see here we get the result of one. But if we go through and we change one of those strings to B, you'll see here that we get the result of zero. And remember it's case insensitive. So if I put in a capital A here, a lowercase A and a capital A are the same. So we're going to get the result of one. But this will have the same bug as scratch because if we put a space in here, we're also going to get a false result. But there are some other things we could do in Python to strip these white space characters. But I'll leave that up to you to go and research online. Lastly, we could print some feedback to the user to let them know if they get it incorrect or correct. So just below the result on the same level of indentation, let's just print correct here. And notice in scratch, we've got the else block. To do an else block in Python, we just need to go back to that level of indentation, the same level as that if block, and put else and a colon. I'm just going to copy and paste that print statement. And I'm going to write, oops, then I'll run our program. I've got our A and B here and you can see, oops, we didn't get that right. But let's make them both A and you can see, yes, we got that one correct. All right. So we're nearing the finishing stages of our game. We've implemented say words, say sentence, ask you to spell and we've checked the result. Now we need to implement this big block here. But this tutorial is getting long and there's a little bit going on here. So we're going to save that for the next video. In that video, we're going to be exploring lists a little bit more deeper, looking up exact values in lists. And we're going to look at a different way of iterating, which you've done in scratch and it's a whole heap easier in Python. So I look forward to catching you in that video. But until then, I'm off to go find a wave. I'll see you next time.