 The writer program takes you a user input describing a card, playing card in the following shorthand notation. So if you know you're playing cards, right? So if you enter, this is the enter here, this is the input, enter a card notation. If you put a QS, then you are going to print the result of a queen of spades, OK? So QS, so you check here if it's a Q, then you replace the queen if it's S and of spades, right? If you get AC, there will be an Ace of clubs. If it's a number between two and 10, then let's say we get seven, there will be seven S, so it'll be seven of spades, OK? You're going to print that out. So we will map that to these numbers and then you print the correct name and then also the correct suits down here. OK, so let's see if we can think about how do we tackle this problem using functions. Of course, you can write this using non-functions, but so the purpose is to use functions. So get back to your basic stuff, those three steps, right? Input output stuff. So input here, the input process, output. So we know the output what's going to be like. This is the output, right? So I mentioned way back in Unit 1 that usually when you do your program, you're going to spend your time designing the interface, what it's going to look like. If you know that, then OK, so this is my output and this example is really simple. So basically you just want print statement. So in my output, I'm going to have a function to maybe just say print result, right? That's all it does. And maybe I'll just do that. So inside here, you can do a function, say a def, a define, print, result like I mentioned earlier. Now, what do I need to print this to the console? I need to print the card, which is the card, and the suit. Well, I guess this would be like the rank, right? If you want to call it rank, I guess what you refer to in cards. So I'll call the rank and the suit, and plus the word off. So in my print statement, in this case, I need to do something like print the rank, and then you could put here the rank, and then comma, and then the word off, and then the suit, something like that. I mean, for this example, it would be really simple like that, right? So that means when I print this function, I have to pass to this function, in this case, two things, right? Two things. And I need the rank, and I need the suit. So I can print it out to the console. So in this example, it would be a very simple print statement. If you want to decorate it, you can print in multiple lines, but this is good for this part. And so to test it, you can say, OK, print result, I'm going to say queen, and then it would have actually the whole word, right? Queen of spades, something like that. And when you run it, you're going to see the result over here. That's a result that you want to use. OK, but of course, we're not going to manually put this in here. I'm just showing you how that's going to do. So that's the output, the input. So we're going to read that from the user, and this is the text. So over here then, instead of saying just get the input, I'm going to use the function to read the input. So you do something similar, maybe get card, right? And then inside here, you need to set the card to an input statement. This is something that we've done before, and this is the text here. And I'm not going to do any validation here, but we do want to convert that to uppercase, so upper. OK, so once you get the card, and the reason why I put the word get here, as you can see, here I'm just printing, when you print a result like this, when a function that has now returned something is a passive function, right? You think about if you give an instruction to somebody to do something for you, then you say, here's my key. Take my card and go home, right? So that instruction is very passive. You're not expecting that person to come back, so there's no returning back. The other one here, I'm getting a card. So I put the word get in front here just to give you a clue that it's going to return something back. I request it, I need something back. OK, so here's my card. Go buy us some coffee. I expect coffee to come back, and also my card, right? So in this case, once you read the card into this card variable, then you need to return it to where? You don't care, right? You don't care where. Whoever needs it, whoever requested it is going to get the card, OK? That's where functions are very specific to what they do, and they don't have any clue what's going on outside of that little world. They only know that, OK, I get something, I do what I'm supposed to do, I'm done. So this will be the get card. You can also call it get input if you want to, but again, if you want to make it more specific, then this would be a better option. OK, so I get that, and then the processing part is you're going to use this card. You're going to receive two characters, like Q and S, and use that to determine using this chart here. So if it's A, then you want to return the word S and J and so on. If it's between 2 and 10, then you just basically return the card value, which is the number itself, OK? And that is the first character, right? The first character, you check for those. The second character, you're going to check for these suits down here, OK? So the process part then, you're going to have a function, maybe something like, I'm going to have two functions, one to get the rank. So you can do something again, say I get rank, and then when I get the rank, well, I need something to check it out, right, to check the rank with. What do I need to check? Well, I need to check these values. These are the actual card. So these are the rank, right? So I can say, OK, I need the rank, whatever that value is. Then I can check those against a list of something. So here you would do, say if the rank is equal to an A, right? Then you're going to return the word Ace. And you do that for all of those ranks, OK? So notice that if you do something like this, if it's a if statement follows by a single statement or a very short like this, I mean, this is OK. Let me copy this. You can see, sometimes it's easier to see this way, but sometimes it's not. I mean, if it's a king, K, that's a king, right? So in this case, if you just have one return statement that it's OK to do it this way using a single line, it's actually cleaner to do it this way, instead of using two lines, because all I'm doing is bang, bang, bang, right? If it's A, return, go, done, OK? So basically, the line looks cleaner and actually shorter. So I'm going to copy this and print a couple of times. If it's A, it's a king. If it's a jack, and it's a queen. So this would be a jack, queen. And then, oh, I think that's it, right? If it's anything else, then it must be the numbers, right? Between 2 and 10. So in that case, you don't have to check it. You just say, OK, if that's the case, just return it back. It must be a number, not A, J, and king, queen. So you return the number back. Again, well, assuming there's no one here, we don't use one. We just have to make that perfect in the entry point. So there you go. That's my function to return the rank. And then I need to get another function to return the suit, right? So same thing. This is if we get suit and need the suit. It'll be passed to this function and same as above. Because if its suit is S, then return spades. And you can copy this four times. So heart, club, and diamond. Oh, I'm going to get only those four, right? So those are my functions to process my information. And then now is, OK, so where do you start? So these are all my functions, you do my stuff. And then this is where your main function comes in. So again, down here, this is my main function, what I do here. And then somewhere down here at the very bottom is the entry point to my program. Call it main, and then the main function invoke here. So I will start here. So the first thing you do is you're going to get the input, right? So I'm going to get the card. So I can say a card here equals to get card. I call that function. And that function up here is going to return the card back to me. That's what it does. It comes back. I got the card. After that, I need to find the suit and the rank. So I just call those. So I'll say, you know, suit, I use the same variable name, is equal to get suit. And it's going to be the card of the second parameter. So I could put up here and be like the rank first. And I'm passed to that the rank of zero, the card of zero, right? If QS, I'm passing the card of the Q letter to that function. So Q comes in here. It matches the Q, returns the word queen, returns it, right, return queen. And then now the rank has the word queen. And then now I pass the second letter S to this function. And it says spades. So I have returned spades to the word suit here. And then finally, I call this print function to print the result. So I can say print result. It needs the rank and the suit. And it prints that out. OK, so we can give it a test and see if this works. So here we go, and put QS just like in the example here. And there it is. This is the queen of spades. And if I run again, if I try a ace of club. So there's ace of club. And let me try the number. Let me just say it's seven of diamonds. There it is.