 Hello, this is Christian and welcome to Unit 5 Assignment. In this video, I'm going to walk through how to complete Unit 5. This is just one approach. There are many approaches you can do however you like, but I'll show you how I would usually tackle this, okay? So our task is to refactor the Unit 3 Assignment, which is the bank transaction application using functions in loop as stated here, okay? So the first thing is you want to make sure you understand what the requirements are, right? For any assignment, any problem. And it asks that we need to implement and create these functions. There's about, I think, seven functions that we need to implement. Okay, so look at each function name and look at the descriptions and what they are supposed to do, okay? So these functions appear, as you can see, the main and the depth balance do not take any parameters, but these down here too, okay? So make sure that is also taken into account. Unless, you know, instruction asks you to do how you like, you are more than welcome to do that. If the instruction does not state that you need to change things, then do not do that, right? You want to follow instructions and as well. So think of it like a requirement for your clients, okay? So just something about, think about. So we're going to add a main function to be the entry point and we're going to show a menu to deposit, withdraw, and transfer and things like that. The get balance function is supposed to return the initial account balance as a float, okay? So that means that it only takes one, you know, account, you know, return it. If you get a savings account, then the checking account and, you know, CD account and so forth like that, right? And make sure you read it carefully. You're going to, you need to return the account, okay? So the function has a return statement. Now the process, deposit, withdraw and transfer, they're all kind of similar. The only difference between these two, the process, deposit and withdraw, and the transfer is that the transfer takes two, you know, parameters as the other two are not, okay? So make sure you follow those rules as well. Here is the example of how you can actually use that in the program. You're going to pass in the checking account, which is the amount you initially have. It processes the deposit and returns the new updated account back to the checking account, right? And the same thing here as well. You do withdraw, then you do that as well. The transfer is similar, except now it says you're going to, as an example here, you know, pass in both the checking and the savings account and then return both totals back, okay? Make sure you, whatever upwards you did inside the process transfer, you have to return those data back so that it will reflect up here in the global variables. Then the print balance here, it just asks you to print a single account balance, okay? So that's that. And then the quit function here, this one is a little bit bad. Usually we don't want to call it quit, but it's okay in this case, because there is a quit function in most, you know, Python programs already. So we're basically overwriting that function, but that's, that's fine. And we just basically print message to Incubi or whatever it is to end the program, okay? So that's the function you need to implement. Down here, more rules. It says after each transaction, okay, you want to ask the user to see if they want to continue doing that transaction. So an example is like once I make a deposit, then I select a check and account or the savings account and make a deposit. It's going to ask me, do I want to continue making deposits? If I do, then yes. And then it's going to, it's going to ask you again to select the account and make deposits again until you quit, right? Once you quit, then take you back to the main menu. Okay, that's what that means. And then the program runs indefinitely until you press quit or exit out the program. And you also want to validate all the input here. Make sure all the menus are entered correctly. If they're not valid, keep saying, telling them that it's not correct, please do it again until they get it right. And here it just said that you are free to add more helper functions. So a good one is to display the menu and display any invalid entry because you're going to see this quite a lot. It's repetitive. So, and, you know, a few more if you want to do that. And again, document your code. Okay. Right. So let's go ahead and go into our IDE. So here is the using spider, by the way, you can use any idea of your choice doesn't matter. But this is ID. So this is the unit three assignment, right? It's just very simple program in the one file has no functions. Okay, no loops in here, just one go and what done. Okay. So just to see how this work and run it over here on the right side. We're going to ask for a check and balance just to make sure if mine is a hundred, if it's negative, should be taken care of, right? Because not allowed. And even though I did not prompt a message, you know, you should send that to zero as you see here. And we check that here. Okay. And then let's say the balance of the check and saving is $50. And I'm going to make a deposit. So make it into the savings account just to show that the balance of the checking will be zero. And let's put, let's say $5. Okay. You see that the result, it's not lying perfectly, but the check and balance is zero because we can make a negative value. And then we add $5 to the savings account in the program ends. Okay. So that is what we're going to do for this assignment. Now I want to use loops and functions. So it's loop and it runs indefinitely. Okay. So first I'm going to make a copy. Yeah, that's fine. We'll keep it as this. So here is what I will do. And so everything here is in the global space. So right away, right away, I got to make this into a main function. Okay. You do that. And then I have to go all the way to the bottom and shift everything over one tab over and then down to the very bottom. I put here a program starts or entry. And make sure you enter the main function down here. You make that call so the program runs. So there we go. We got our main functions very broad. It functions are meant to be very specific. So make sure we do that. First of all, I don't want to see all these here. So if you click on this icon here, it says maximize your current pain. If you do that, it not only maximize it. It also shows you over here in the left, right pane, all your functions. So we just created the main function that you will see here. Okay. And then the more you create it here, it's going to show up. The main variable in the global space should show up here. So as well. So for example, I put like a test to not sure I didn't show up here, but usually it would show up here. And I should wait. Okay. Usually, I mean, other ideas will show up, but this one doesn't show up. Anyways, so you got our main function. So the first thing I want to do is do the easy one first, right? They quit example. What do I quit function? What do I do right here? And what we're going to say, I want to say, um, I'll just comment like this. Maybe new line, a tab. We're here. Goodbye. And then just have fun with this. I'm going to put some emoji here. I used to do this a long time ago. Like this right there. Bye. Okay. And then slash for a new line, just give enough space. And yeah, we'll see how that goes. Again, feel free to make it neat. Maybe you can even add like a pound sign and then multiply that like something like 30 or so. Okay. So that you can duplicate this. I think the, um, make it so that it looks like that. Okay. That's the quit function. Okay. And then the next thing is, um, the check and count. Right. So this is for the getting balance. We're going to move this out to a function. So call it jet balance. It takes no parameter. If you remember the rules. And what we're going to do is we're going to ask the user to enter some information here. Okay. So we're going to add ask, let's say it to account. I'm going to say, um, we need a slope. So I'm going to say input, um, I'll put a tap here just to give some, some space enter, uh, amount. Notice I did not say check an account or save his account because I want this to be reusable. Okay. Well, that means that when I call the check on account, you know, it just say check an account. You are, you know, free to be creative, but I'm just use that. And so that means when I do the checking here, I don't need to do this anymore. All I'm going to do is I'm going to say get balance. Right. Call the function. It causes function. And once it got the balance, remember, I need to check it, right? I need to check zero or not. So these two are repeated. I don't need to need, need both of those. I just need one. So I'm going to move this up here to make sure that the account is indeed not zero. Okay. If it is zero, then it's going to be set to, I mean less than zero, it's going to be set to zero. And then finally, I didn't need to return the account back. So once I returned it, it's going to assign and plug right into the check an account. Okay. Um, mis-type, mis-type. That's the validation part here. Very simple. And then this saving is the same. So those you see here, the redundancy is already taken care of, right? Because I'm using a function to do that. If I add more savings account, meaning we're checking one, checking two, we have a CD account. It's the same idea. Okay. So that is basically for that part. So, um, and then the next thing is the transaction, right? I'm just to show that it does work. Okay. We're going to go ahead and just run this for now. Just make sure it's still working. And you should test as you go. Um, so it's just easier to check for bugs. So notice the enter amount. I did not say what it is. So as you can see, it's a little confusing already. Right. So you usually want to say something like, um, you know, enter, uh, check, check in, check an account or something so that the program know what it is asking of you. So we're going to print a message here for a second, but let's say that what we know that it's going to be checking. So I'm going to put here again, a minus 10. The second is going to be a hundred for the savings. And then again, if I do a deposit into the savings account, let's put 200 here. It should be zero and 300. Okay. As you can see here is the way it is. Okay. So it's working fine. We did not load the quit. I should have done that, but we shouldn't have a lot of quit. So go back to your code here and, uh, not this one, this one up here. Okay. You want to show a message when we add the check on account. So I'm going to put here, but just say fund the accounts. Okay. So I want to put here French message, uh, checking. I'm not very creative, by the way. So it's something like that. And then we do the same for the other one. The copy and paste it right here. The next one. This is the savings balance. At least then we give the user some idea where, what's going to happen. Okay. So we got that funded. Now this is the transaction. You put here a message or a comment like program, the program will run indefinitely. Until user exits. Okay. And then we'll quit. So basically we're going to put a loop here somehow. Okay. So we'll put here raw loop and I just pull out through a force. It'll be true. Once we exit out of that, then you just basically break out the loop. You can also create a variable like continue or something like that and then set to true and then you set to false down middle of the body. That's okay too. I'll use this approach. And once I put a while loop here again, all of these here will be shifted to the right. Okay. So it goes like that. And we'll decide when to shift back or not because right now we want to show the program works. So it runs everything to the end of the program right below here. We print the message. So this is where you would ask the user. Do you want to continue or not? Okay. So let me collapse these as you can see. Okay. So here and then at the bottom of the while loop, I'm going to ask the user. So what do we ask? Just a simple transaction, right? So something like do you put here or just say choice is equal to input. What do we say? Say continue, continue the program, right? Actually, no. Why should we don't do that? Because the while loop only has a menu. I forgot about it, right? We're going to have a menu right here. So it keeps running until we quit. So we're going to add here the input, another one, which is the queue for quit. I'll call it X for exit. Or quit. It doesn't matter. You can call it whatever you want. That's entirely up to you. But I'll call it X for exit. Okay. And then now once you press X, so if you go down here, I don't have it yet. But I'll put it right here. This will be a live. And if transaction is equal to an X. And then we just put quit. We call the quit function. And then we're going to exit out of that. Okay. We break out of that program. The loop, you know, breaks out. And then we quit. You can also do this. You can do that. We just break out and then call the quit function after the while loop down here like this. Okay. Because also the loop, by the time once X out the program, then you can call the quit. Right. So either way will work fine. So again, let's just test and see if this still works to go. Now we're checking balance. Let's just put here 10. Seven is 20 deposit to the checking. Let's just put 50 bucks here. And you can see that it deposited. And then it keeps going back to the loop again. Right. And I want to exit. So if I type X. And then here, it did not work because I probably, yeah, I did not get the X. Yeah, that should actually quit. Let's just do it one more time. Okay. So it actually prompt for a input, which is kind of weird. And that's supposed to do that. We just kind of quit. Okay. So he quits in and put the message here nicely. You're right. So that's working. All right. So that is working. Okay. So I'm going to put this back in here just so that it makes sense because you want to quit message right away. And when you exit out, I'm not going to print it again down here. Okay. So then the transaction part. First, let's get the menu. This part here is the menu. I'll make it a nicer menu. Let's go up here. You're going to print a function, create a function. This is a helper function. I'll call it main menu takes no parameters. And I'll make it so that has a new line, give it some space. And then use the same idea up here. I'm going to pass this. Building down here, the top and maybe the middle. And then at the bottom like this. Okay. I'm just putting that so I know where it is. And instead of the pound sign, I'll use the equal sign. So 30 across. This is the top of the menu. I'll put some message in the menu. And then the bottom of that. Main navigation. So in here, I want to put things like print with a tab. Bank transaction. Okay. Let's go to the top. And in the middle here is all my menu options. So print. I put a tab here for a V. Okay. V. And then put another tab. And this would be the view account balance. So you get the idea. Right. So the V. I didn't add it here. I'm going to put a V. And how do I duplicate this? I think say. Oh, control down. Yeah. Oh, control down. Duplicate your lines. So one is for the transaction. I'm going to deposit, withdraw, transfer and then exit. Okay. So those are your five menu options. So this is the deposit. The withdrawal. Transfer. And then the exit. So this is the exit. And then here. Just exit. Right. This is. This is a view. This is one here is the deposit. And then this is withdraw. And transfer. Okay. I'm going to remove this. Actually you're going to replace this. With what I have up here. We'll see how it looks. I think that looks. Probably should be the same as. The quit. The width of that. So when I do the transaction. I need to then load the menu right here. So instead of using this part of replace this. I should not keep that. I'll put here the main menu. I call that function to load the menu. And then I get the transaction. Okay. So this probably gone. I still need to make that. That transaction. So really. This will be. How do I do this? It's going to be. Initiation of the really input. Right. So you read the input. I need to select these. So what I had earlier was actually. I do this like this. Let's let's create a function. I'll call it. Get transaction. Type. Okay. And this function is going to return. These. Transaction up here. So notice I did not put that inside the main menu because. Main menu is supposed to just display the menu. So this one here. Get transaction type. It takes no parameter. It's going to return a type. Whatever the type is, it's one of these, right? X V D W T X. Okay. So that here we're going to put here. A transaction. What I showed down here earlier. It's going to be. Input. So notice I get already showed the menu after that. I just need to have him pick the. Option. So I put here. Pick. An option. They put an arrow here. Just make it nice. And once I read it, the either a W. D V X T rate. I'm going to go ahead and strip any. White spaces. This is for both trailing and leading white spaces. I'm going to grab just the first character. And I'm going to uppercase it. Okay. So that's what I'm doing. And then now I need to validate the input. If it's not in any one of these. Options that I'm going to prompt the user to keep entering. That. Right. So here I would say if transaction. Is not in. The string of W. D. V W. T X. Doesn't matter. I guess. If it's not in one of those, then I'm going to. Prompt. I'll call the function and valid entry. That's what their function comes into the picture because I keep doing that couple of times. And then if it is correct, then I'm going ahead and just return. The transaction. Right. Return it and we're done. But remember this has to be looped. So up here you put a while loop. And you shift everything over. Like that. Right. So I need to create a function to display. The invalid entry. I could have it so that it displays a. A default message if I need to. Or you don't have to. It depends. It depends how you want to do it. You can make it flexible. So that I can pass in, you know, my custom message would have wanted to do that. Right. So it's up to you. So I mean, if I do that, then my function, I can have a message here and I'll set a default message would be something like invalid input. Try again. So if this is the default message, you can keep that. If you don't pass anything to it, you keep it default. Overwrite it with something else. Okay. So you put here print. And I'll use the function. Just to say, like this slash in. Just a new line, some space, some asterisk. And then I'll put here the message. Oops. In the wrong one. And you exit out of that. And then again, more dots. Like that. And then slash in for a new line. So very simple message display to the user. Okay. So let's see if this actually works. So save this. And run again. So here we go. Account will be $10, $20. And here are my, okay, it's kind of bad. I've got the T here. So if I put like an H, right, there's no input there for age. As you can see, it loops that until I get it right. Okay. If I go ahead and do a D notice again, the other case located doesn't matter in this case. I'm going to withdraw into the checking account of $50. And then the program runs back to the main menu. Right. Remember that the requirement is that as long as making a deposit, I have to keep asking the user to make a deposit, which I didn't do yet. Before I head back to the main menu. But since I'm here, I'm going to go ahead and do an exit to quit the program. And as you can see, this is not working right. So somehow it's keep asking that question. It should not issue just quit. So that's, there's a bug here. So let's find out why that's happening. Okay. When I type X, let's do this first. I forgot to put a T in here for the tab. So I lined them. When I type the X, I load the quit function. And I'm supposed to break out of that loop. Okay. Once a break out of that loop, the while loop. Let's see why is it not go down here. Yeah. I should just quit. Why is he asking for? Interesting. Okay. We'll have to figure out why it's not working. Okay. So now we got that transaction type. We check in the checking with savings. This part is again up to you how we do this. You can do it up here. Or you put inside the deposit or a couple of ways to do that. I will probably, let's see, we got the quit and then we got the transaction. And if it's a D, then we go on to ask the, what should we do here? Excuse me for a second. Okay. I just need some water. Okay. All right. So deposit. So we need to ask. So up here I asked right away, but if we need to do a deposit, you want to be clear, right? Select the account for deposit with withdrawal. You want to say, select an account for withdrawal and transfer and so forth. So this one is not, doesn't really serve really well. And so what I do is think about again, repetition, right? Again, again, again, I'm not going to like copy this, for example, move that in here every time I do that deposit. I do a withdrawal kind of similar, but you see the redundancy here, right? So I do it three, four times. So instead of doing this way, I'm going to add a function to get these type of input. And you can create one to maybe just select the account. So I'm going to copy what I have here and copy that. And right up here we're going to create a function. I'll call it select account. Again, we're not adding any parameters here. All I'm doing is watch it. I do want to make sure that I select the correct account, correct account. So for a deposit, it would say select, you know, select deposit. And then for a withdrawal, you will put something more meaningful. So I want to say, is this a select? I want to put something like, for example, let's just say deposit and two, and then either checking or savings, right? So I want to do that when I make the transaction down here. If I go into make a deposit, then I want to do something about the account is equal to select account. Okay. And then which account is it when I call this? Because when I do this, I do down here as well for the withdrawal. I do here also for the transfer. How do I know which type is it? So this we add some data to this function. So this one here is for deposit. So maybe I'll put here deposit into, I'll pass that as a string right in here, right? And they are replaced this with a text. And then writing here is what that unique text is going to be replaced with. So you can put that, you know, text here like this, and you use that F function to format that. And just make sure you close. Yeah. I think that's, that's, that's fine, right? Okay. I want to do like I did above. I'm going to strip any white space, just pick the first character and then uppercase that. Okay. And then I'm going to validate that. So let's say just like above, I'm going to copy this. It's the same right here. So if the account is not in the S or C or CS, then it's invalid. Otherwise go ahead and return the account. Okay. In this case, I'm not asking for the amount, right? Because I'm not doing the amount here. I'm just basically get the account type, either the checking or savings. What, um, before what am I doing? I need to get the type of input, right? For that, either a deposit transfer or withdrawal. So I make that withdrawal menu as a deposit into that. And then this is what I do the amount. So you copy that code right here, enter the amount. So this whole thing now is now removed. Okay. Deposit into, and then you get the amount. So I'm going to go down here at the amount here and the amount here as well. And for the withdrawal, I would say the string would be withdrawal from. Okay. I'll choose the, I'll choose the from. You can make it different. And for the transfer, LJ transfer from as well. So down here, I would say transfer from. And then that account and you enter the amount and so forth. Okay. We'll see for now, right? It may not be, um, here, but for now. So I'll go back to our deposit right here. You know, another easy one is that the view account, because I want to put up here. It just nicer to put up here because less to, um, to code. So I'm going to put here. How if the transaction type is equal a, um, a V then I'm going to put here, uh, show a function to show the balance. And then you just basically. And they're also, let's see if I show the balance. Yeah. I need to create that function. Okay. I'll put that for now, but I'll put a passive for now. Okay. I'll come back to do later. So the deposit. So we got that account. Deposit. You enter the amount. Um, and then we check. Okay. If a month is zero. Yeah. This one here, um, we can leave it as this or I'm going to move this into the process trans deposit because this part is going to be a process inside the checking or the savings. Okay. So we're going to create a function, uh, to, to process the account. So here I want to do, we'll just basically this, I get the, get the account. I'm not going to do any reading here yet. I'm going to go and, uh, go directly. I'm going to cut this out. Go directly to the account. If it's a checking, then we'll do something like this. Put a checking here. Equal to process deposit. And then this is the requirement. Right? We pass the checking account to that. And the function will return the check and account back. Okay. So these two will be not needed for now. I'm going to comment that out. Control one. I think, yeah. Now we need to create a function deposit checking. So appear a process. Deposit. We're taking the account. I don't care which account it is. All I know is that I've received an account. Then once you receive the account, you do need to verify, you don't need to do that because you know already that it's going to be a checking account, a savings account, or what account it is, right? All you have to do is just to perform the logic. Okay. So this is why you do the read input here. So you read the account for the amount. You check it with zero or not. Otherwise you put zero. Okay. And then you add to the account. So this part down here, this plus right here, right? And you can, let me copy this now. We're going to take that out. Okay. And we'll put it inside this function right here. So instead of checking, it would be just the account. It's a generic account type, right? You update that account. Your print has to deposit it because you don't know checking on or not. You could just say into, you would just say deposit into, I don't know, not checking anyway. Into just a deposit. Okay. Just just like that. It's very generic. And then you're going to return the account back. Okay. We turn because we're not dealing with any global variables. So if you don't return it back, when I make the update, my checking account, which is local to the main function, will not be updated. That's why you need to make sure that that's been updated. The savings is the same thing. So this time I don't need this anymore, right? I just going to say savings equal to process the deposit and then pass in the savings account. There. So both my accounts are now taken care of. And this part is almost done. So once I make that deposit, then again, the rules is I have to keep asking if I want to continue here or not. Now you don't want to put in here the loop. If you loop in here, then you are locked in to this account. If it's a checking, then you're locked into checking. You want to be able to select the checking or deposit as well. So you loop outside the transaction, right? So right here. Okay. So that means this whole thing needs to be in a loop. So have that over. Once I'm done, I'm going to prompt the user for a or a, if you want to continue or not, right? So I can say something like while true and repeat because I need to validate input. The choice is equal to input. I would hear another deposit put here like yes and no. And then you put like that again. I'm just going to put strip up any white space. The after first character only in uppercase it. So here if choice not in while and that means that it's invalid. So you put here invalid entry. Okay. Otherwise, you can just go ahead and continue. So up here, I put true and false here. You can do this way. You can just, you know, a couple ways, right? You can put here else. If the choice is equal to a N. If that is the case, then you're going to break out. But how do you break out of that? Right? How do you break out of that? Because you break out here. You only break out this loop. You still locked locked in here is still going to continue. So doing this approach, you will have to get out of that loop. And then it was like this. If it's valid. And then you break out here. Okay. And then this part is going to be outside of the volume. Like this. This whole thing here is just basically to validate the input. It has to be a Y or N. Can I have any others? If it's a Y or M, you break out this loop and then you check the choice here. If it's a no, I'm done. Then you break again. You break out of this loop here. Okay. So you're done. That's what this one does. And again, just test it. Make sure it works. Great. Just for the deposit. So let's see. Put $10, 20, and then make a deposit. A port checking account. $20. Here we go. It says another deposit. We're here now. If I type a T, notice again, invalid entry type again. If I put a yes, then it should take me back to another deposit. As you can see, deposit into, let's say, saving this time $5. And now again, I'm going to say no and we're back to the main menu. Okay. So that's what this whole thing is for. This whole thing is just to make sure that the user is able to continue the transaction while they're still making that deposit. Okay. So this approach is fine. How are you like it? That's okay. I'm going to change this a little bit using a different approach. So instead of doing this way, you could do this. Like up here, you can say transaction, continue transaction is equal to true. You put that right here. You force that to be true. So here, then you can say your choice is true. Then you can, if it's no, the long way, you put a continue is equal to false. Right. That'll work, but it's just a lot of typing, right? It's redundant. So the only thing that is true or false is whatever this entry is, either while in. So the shortcut to do this is basically going to replace this break with this line like that. Okay. You set to continue either true or false based on the y or n. So you can pick one. So if choice is equal to a y, then it's true. And then you break out of that loop. So you break out this loop. It's going to go back to the value outside here. You check the continue transaction. If it's a yes, then this is true. Repeats it. If it's a no, then it's false. It terminates the loop. Right. So again, just to test, make sure this still works. Run. Put one, two, and then deposit, saving $12. And if I type J, right? If I type in y, it should continue. As you can see, as $5, let's put it no. And then we're done. Exit out the program. Okay. So that's one technique you can use. And I'll keep it here for just for this one here. So the deposit is pretty much done. So the withdrawal will be kind of similar. I use a similar approach. Okay. So I'm going to copy what I have here and add that to the withdrawal right below here. And then shift everything over like that. The bottom will be the same. I'm going to copy this whole thing right after the, the else clause. If something is checking or savings than that. So you're right down here like this. Like that. Okay. Is another withdrawal. Right. Something like that. And then we can then hit W I think. Yes or no. Same thing. And it's going to go back here and continue or not. So same thing. There's a mount here. I don't need that anymore. But it'll be very similar to the one above here. Notice we continue. We get the account type. We pass in the function to parameters. We come back. And if it's a checking, they will put here checking equal to process. With draw. Okay. And I put here checking. Just like above. And then this will be the savings. Right. So this part here again. We'll copy this for now. We'll move into the function called process withdrawal. We take one parameter just like the one above the account. Put that here for now. Read the amount. So we're going to copy this whole thing. Put it here. It's the same process. And then if the amount is less than not checking by the account. It's the generic account now. And then just say account words were draw. I don't specify the account this case. Okay. And then otherwise it's sufficient fun. And then we're going to go ahead and then return the account back. Okay. I think that is. Yeah, we turn it back. Let's do that. So I have some space in here. The amount. Let's let's do this. So it makes it makes sense. Like to be consistent with my layout here too. Does it matter? I guess I'll fix it later. All right. So we get that. And then, yeah, let's let's let's change it. Let's be consistent. So we got the process coming back. And then the. Saving will be the same copy that put it here. So this whole thing I don't need anymore. Put it here. Now you can see it's much shorter. This is the savings account. Just kind of copy and paste. Okay. And then we did all that. We got our transaction done to come back out. You want to do more withdrawal. Yes or no. And then repeat the whole thing. Right. So again, say just make sure it works. Go ahead and run. And let's try 10 and 20. I do a withdrawal. I check an account. Let's put $1. What's withdrawn? More withdrawal. Just say yes. Go from the checking account. Let's put here $50. It should be invalid by insufficient funds. And then you keep adding withdrawals. Right. And I'm done. So back to the main menu. And then exit out. So that works perfectly. And then the transfer will be the same. Right. So again, this whole thing, I'm going to copy this. Go down here. After that process, I'm going to put the continue on the top. Right above the account. And then I'm going to shift everything. Yeah. Over one tab. Okay. So we don't need the amount. Okay. This logic is going to be inside that function. So when I take that out and the function will be, you need to pass two things that the checking the savings. And it's going to be a process transfer. The checking in this case will be the source. This destination is the savings account. Right. So let's go ahead and write the function up here. If it's hard to go up and down, you can also do this. Right. Where are we? Right here. Right here. You just go and write the function right here if you want to. Right here. So you can see. I need the source account. The destination account. And then you put information here. Okay. So the source. If the amount is less than. Equal the source, then the source. Is being deducted. Right. The destination will be plus. Okay. This machine, you do it right. I didn't read the amount. I need to read in the amount. Okay. I miss one. So let's copy one of these guys and her amount. Okay. So in here, what I had earlier. You put that here. Okay. Read the amount. And then was transferred. And then sufficient fun. And then finally, you're going to return both of them. So return the source. And the destination. Okay. So close. Right back. The source destination. Make sure you do it right. If it's the savings account, then you're going to add here. You're going to swap the two because now the source is coming from the savings. And then it's not checking. So the order here is different. Just make sure you get that taken care of. So now if it's working, then, um, you know, you find you, it should run. Even though I had a function here. Okay. Because you can ask functions. So again, just test and make sure it's working. Go ahead and run it. I'm going to go ahead and put 10, 20, do a transfer from the checking. Let's put $5 into the savings and then just put no here. You see that the account is deducted by five and we add a five to 20. So we get $25 from the initial account. Okay. So that's perfectly works fine. And then now once it's working, we're going to move this whole function. Cut that out and move it outside and then highlight the whole thing and then shift tab. Here we go. We got our function to do that transaction for us. And now code is getting leaner and leaner, I think, right? And not as lean as you would like to, but still leaner. You can make a leaner if you want to. So basically we got everything done here. Okay. So this part right here, this part is going to be inside that print balance. Okay. So we'll have a function call show. I think I call it show balance. Show balance up here. And I'm going to pass in both accounts, the checking and savings accounts. Okay. And let's remove that. So up here, I'm going to have a function show balance. Take on the checking savings and put that in here. All right. So this part here, I'm formatting the output. Oops. Sorry. I'm formatting the output to look at nice so that I can print down here. Okay. Which is fine because I want to be, you know, right justified. That's what this means. This whole thing here, the amount, colon and then the angle bracket 15 means like accumulate. I mean, reserve 15 spaces and then right justify. This is a left justify. Okay. So just for outputting stuff, but I'm going to make it a little different because one of the requirements is that I need to create a function call get balance. So somewhere down here, I need to have a function like get balance. And I take an account or get the account. And I'm going to do is just basically not, I'm sorry, not get balance. We already got that. It's the print balance. Right. Print balance. And we're going to print this, each of these account here. Notice I did both here together. So this account print balance, it's supposed to do only one thing. They're walking only. It's supposed to print the balance. So let's say that we're going to do a I'm going to copy this. Okay. Copy one of these. But right here. And then I'm going to print that account. So put here. F tab. And then we'll put the Mississippi account, not checking checking is equal to checking and format that using this approach. You can do either way. It's fine. If you don't like that, I don't like that one. Let's use the other approach. Let's do this way. The F. And then account. Right. Commas operated decimal to places. Okay. And then you wrap that inside here. And that's it. So tab and you put here again, dollar symbol, the account. And then I want to be, let's put 12 instead of 15. Let's see what happens. And then need to close that. Like that. Okay. So that means when I print the account, I knew I don't need to do this. Okay. Because I have this function printed for me. When I run that account, I will use the same heading as one of I use above for the, the menu. I'm going to go copy my menu. This whole part here. This whole thing basically. Yeah. Copy that. Put it down here. I should move this up actually. Like that. And we'll put it here and not bank transaction, but put here bank account balance. And we're just going to remove that. Okay. So we have the top bar. I'm going to separate this easy to see. And then this is the last line of bottom. And okay. So I don't need this whole thing here. So in between I'm going to call the function. I'll print a message tab or call it checking. And then I'll put the account here. I do want the same for the other one. So here print balance. You pass in the checking account. Okay. I'll copy this. And you do the savings account. We hear the savings account. Right. Let's see what that looks like. And let's see. It's working. I don't know. Let's find out. So I want to show. I should have to quit first. Okay. Let's do it again. So we go. The amount would be that. And then let's do that. I'm going to view the balance. Okay. So up here, right? You can see it. It's showing right here checking, but it goes to the next line. I'm going to show right over here on the right side. So I want to remove that carriage return after the checking here. Okay. And you can see the comma is separated. It's right. Justify. It should be. And so let's fix that by going to the print function. Could hear a you override the end. The end. Attribute. You put a empty line like that. Okay. Or double code. It doesn't matter. Okay. So that's the carriage return. That's all it is. And then we're going to continue from the next line. And then after this print function, and we print down here, we're going to carry it to return. And then we have. In alignment. I want to put another. Maybe put another white space down here. I guess. Just giving enough space to make this look nice. Try one more time. I'll quit first. And then here we go again. Some numbers and then. If you. Here we go. Right. Oh, we've got a tap here. So much can see is much nicer. I probably should put a tap here. So I'll just after the savings. I probably forgot to do that or something must have happened there. Maybe my number was too big. Okay. So at the bank with a T here. And notice that when I run the app, it shows the balance back to the main menu again. So I was like, oh, where'd it go? I have to scroll up. So I normally like to do is you put a pause right here. After I show the menu. I mean the balance. I want to pause here. And then you hit enter. You load the main menu. Okay. So you can do something like. Like right here, maybe I put a function. Pause screen. I just put it in input. We're not going to, we're just going to read it off. Okay. So it's something like press any key to continue. And you put like that, that, that, that. Right. So after I load the, uh, after I view the. Account like right here before I quit. After I show that I'm going to put a pause screen here. It pause for a second. We want to press enter and it goes back out. Right. So here we go. Do it again. So I put a balance. Let's put a thousand. And then 2000, 20,000 and then the view. Okay. So notice again, my screen pauses. Right. So I can see the account. Yeah. We get a tab down there. And then, uh, you know, it waits until I hit enter. And it shows the menu. Okay. So that just adds some nice feature to it. Um, that is all. Okay. So. When I show the account, somehow it's not giving me that. Uh, is it because I too, I have too little wet space. I don't like that. See when I print. Put a tab here. That should be plenty already. I don't know. Um, see up here, check checking. Yeah. Just, just a design. Okay. If I put, I mean, if I enter small number, like, then. Oh, still not tab. Okay. Okay. I want to put a tab after the savings. Um, maybe because I did not have, um, enough space here. I don't know. One character over maybe like that would do it. The trick. Yeah. This thing really bothers me as a, as a coder. Okay. You know, I like it to be kind of perfect. Okay. So yeah, that little fixes it. Right. The white space. Um, it makes it nicer. So I think we're almost done here. We've got everything already in place. Um, I got. Yeah. So we got everything in place already. Um. Yeah, pretty much that's what we need for this assignment. All the functions, but you can see it as you look at my code. You see some redundancies here. Okay. So this part. And this. Right. And this is all the same. Okay. This is also kind of similar. Right. From, from here to here and here to here, you can see almost identical. So you can think about refactoring this to make it a little bit even better. Okay. So, um, another way you can refactor, make it nicer to be moved, these, especially this part here is the same thing again, again, is to move that into a function and maybe, um, add a function. We're going to add a function here. Um, let's, let's cut this out. Okay. We'll add a function. I'll just copy that up here. I'll put a function like a continue transaction. And we add a text. Want to make that unique or not. Um, let's see continue transaction. Yeah. Because it, you'll make an, not a deposit, make another withdrawal. Right. So we want to text message to be unique. But up here, we should basically paste that in here and then move that over. Like that. So I'm not a deposit. I'm not aware of this. So instead of, so in this way you can move this whole thing out into, because each of these is unique into a constants. Okay. Um, and then so, so for now I'm going to replace this whole thing with the text. Right. What do I pass to it? It's going to be yes or no only. And then the entry here, I'm not going to say this anymore. I'm just going to return it. Okay. So we don't want to do any break here. If it's valid, then we basically return the choices equal Y or not equal Y. So true or false. So this one here, as you can see how phrases continue transaction question mark, right? Either yes or no. He returned a Boolean value that down here in my saving, the deposit here. So this whole thing. Right. I need to know whether I should return or not. I still need to check the break or not because I need to continue the loop here. So you can do something like this. Oops. Oh, what I, what I do. Okay. Go back down here. Right. It's going to do right here. I'll do a. Continue. Transaction. Pass in the message. What message is it? This message right here. So this message will go inside. The string. Okay. I pass the message over and it's going to return back true or false. So you could do like a choice equal that. And then. Right. Just like before, because we already check, we already verify when coming back. It's true or false. I could do that. Or I could just do this continuation is equal to that. Right. This whole thing will be done because. Coming back true or false. And this is actually kind of bad because. Notice how I did it. I use a function as opposed to variable name. And we, I'm replacing that variable name there. So this is kind of bad how I did here. It's redundant. Right. Okay. So therefore my function should be different. And then I'll be, I should do a little bit differently. So now. To effect on this part, I just show you one here. And you can replace the bottom if you need to. Okay. So this part can be refactor by doing this, put true here. And then, you know, when you come back. Right. You can check to see if this is true or not. I can say. If. Not. Continue transaction. Then that means don't do it. I'm done. Okay. So this whole thing will be removed. And then this is redundant. So I could just do. So I could just replace this whole thing. With this function and remove this. Okay. What happened here? What I call it continue transaction. True or false. The true or false. It's not liking me. I don't have a. It's not a variable anymore. Why is it. Thinking it's a variable name. It's not a variable. It's a function. They're right. Continue. Make sure I got it right. Yeah. I'm not sure why it's doing that. Let's see. Okay. So. And again, X out. Again. 20. And then put deposit. Okay. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. Checking. I'm using a local variable here, and it's causing the problem, OK? So if you can see if I turn all these off, then you're going to see that the error goes away because it's causing that. So that means I could not just leave it like that. So, well, in this case, let's do this. Let's remove that. We'll put here true, OK? Remove that, true. And then this whole part would be that. And this would be just that as well. Now it's yell somebody. What does it do that? Unident, oh, indentation. OK, so here we go. It forced me to do that because it's local variable. So here is one version, and I will say the other version. I'll undo it, save the other version back as well. Give you an idea how they work. So one approach is like this, and I'm using functions to shorten my code because it's repeating. But notice, again, the text, it should say not deposit down here, another withdraw, another transfer, OK? So it makes sense, right? Otherwise, it would not make sense. 10, 12, with deposit, checking as put $5, $4, not deposit, yes. Savings, $5, and then no. And then let's go to the withdrawal, withdrawal from checking, $5, another withdrawal. You can see it's working nicely, no. And then we do a transfer, and then transfer from checking to savings, that's $5, $4. And then no here. And finally, we do the view, and then we view the checking information, and then we exit out the program. Great. So there you go. One solution to this exercise. Now, you can go even further because all these x, v, and d, and c here are confusing. What do they mean? Why do you need them? Why they even here? And that is we have constants coming to the picture, OK? So I'm going to reflect one more time, and it will be done with this one. So first, let's go and create a list of constants. We're going to gather these, and I'll put here for now, I'll move it up. So here will be like transaction types. I'll put here I use the w underscore for just to say that these are constant, but also private, right? Not really private, but just to distinguish them from other variables. I'll put here a letter v, OK? This is the deposit. Then the letter d, and then I'll duplicate this. This is the withdrawal. This is the transfer. You can't see it there. And I have one for the exit. And you have the checking, and they have the savings. OK, so these are your single characters, right? So w, this is the t, this is the exit, c for checking, and s for saving. OK, so now the view account balance here, go down here. I want to do the view, replace that here. My savings go into the s for all the ssr. I don't have any here, but I don't really use it in this case. So it's not really a matter of using checking. So instead, I should just ignore this one here. The checking is used. Here is the checking. And here is also the checking, and then here too. So now you see it's all variables. And then we do a deposit for the d, and then we have a withdrawal for the w. Let me move the white space here. And then the x will be the exit. OK? So you can see now we don't have any hard coding text except for these. So another set, right? Another set of constants, you can add more to it. So I've got to go up here, add another group of constants. These will be transaction messages, I guess. Put here, continue, deposit, put the message, another deposit, just copy and paste this. OK, so we got that one there. And then duplicate, continue withdrawal, and then we have continue transfer. I'll copy down here. Well, yeah, just type it. It's easier now. And then this is the transfer. OK, so, and then down here, we're going to go and copy these down here to the deposit. I don't know. This is the deposit. And then this is to continue withdrawal. And then we have to continue transfer. Yeah, and I'll leave these as if for now. You can add if you want to. But those are the things that you can manage in one place up here. And then you can move this all the way to the top, OK? So just they don't belong here. All the way to the very top. Like right below the information here you can put here. I don't know you can call it constants. I guess you could call it constants. This puts a bunch of like, you know, there are messages here or whatever. I'll tell you like it. OK, constants. And then all of these will be your functions, OK? So again, just separate these out. Make it kind of nice. And your function begins here. And you can move this around, you know, arrange it. Put comments in here. So I did not put comments, but you should put comments in here. Explain what this one does. I'll do one example for you so that you can understand what's that one. That's so for example, the gap balance. I like this one here, right? So the gap balance you put here. Something like reads, initial balance from console. And then you're going to rejects negative values, right? Balance and set to zero. And then you're going to return it. So here it returns the account, OK? So that's what this one does, OK? And then here it is displaying menu and the same thing. If you return something, you have to return the transaction, return something. So the user knows, and so you also know what's going on here, right? I think that's all I have for this one. So I know it takes a long time. But you can see how I walked through the whole process of converting that into functions and many loops in here. And I also went back and refactored the code and self-worked. OK, so I think that is all. So thank you. And if you have any questions, feel free to post your comments or shoot me an email and let me know. And I'll be more than happy to answer. Thank you so much.