 Hi, this is Christian. So in this video tutorial, I'm going to walk you through how to complete this exercise Okay, so it asks us to create a class called student and the constructor is going to accept the name of the student and A list of all the test scores Okay So these are the methods that you are required to create in addition to anything you want to do But these are the minimums, right? So we have a getter. We have two getters here three getters and one setter right and here is a sample Data for example, if I have the student may enter is this this is a list of my test scores and You can stitch it is to object this way by passing the name of the student and the list of test scores Okay And then if you want to add additional scores Then you would call the add a quiz function and then pass the score to that function Internally, it's going to add this data to the existing list Okay So when you do that your test scores will grow and you're going to get a different average every time Right first. I want to just copy this and put it to the IDE. So we have some References right so first things first I'm going to maximize the screen here Create a class called students. So so class call student Okay, we're going to can create a constructor called under under in it under under for himself and Asks out to use the name and a list of scores. So I'll just call it scores Okay, notice the couple s. I mean the the plural here means it's a school list You can call scores. Sometimes you can call this school list It's whatever you do is until after you but you put plural so you know that is a list of scores, okay? And then we're going to initialize these right away. So self that name is equal to this name and Then self that scores is equal to the scores now It also say that you are a modern welcome to add in the other notes a default score value And so that you can leave it like this That is a default value the default value you can leave it out now like this if it has no name Okay, why you do that? Well, because maybe when you create a new student object like this Right You don't want to pass anything to that student class Okay, if you don't include this default values, you would see that if I do it this way It's gonna crash. Okay, you see that right here. It says I need two Arguments because I have two here right, so that's why if you include the That default values then now if I run it it should be Okay, right. No problem because these are the default value All right, so that's that and again this already instantiation, okay All righty, so we're pretty much done here for this part, but let's complete the class so we need to create a A getter or a setter or get it first get a name self We just basically return the self that name Let's say for that one We need to get a total score Okay, so we turn something a total score. Maybe we have to create a Variable called total score. So let's go up here and we can create one Okay, put zero for now and Then we need to also return a get average score Okay, so here return again Itself that AVG score maybe something like that So I'm just doing something like this first and then you can always go back and refactor. Okay, so AVG score Maybe we're here also set to zero initially. All right, and then we have to have an ad quiz method That takes one score value. So this is the setter. I put notes here These are all what's called getters Okay Get a methods. This is the setter method Four methods So we have one call ad score and We have just the new score notice again. It's a singular that means that we expect that to be just a single value in here, right, so We're going to Update the list of scores. What do we have here? We're gonna append it to that score, right? So self that scores that append the new score So we're not returning anything. So therefore that's why we call it setter. We're just setting that All right, and then now the question is how do we calculate the total score and the average score? Okay, so how do we do that? So before we Return this thing we have to calculate total score, right? So we will say a total score That means you have to get the sum of all the data into the scores list Now in Python, there is a sum function that you can pass in a list of numbers like this If you do that, you get the sum of those numbers. So we'll use that to get the total score Okay, the built-in function. Of course, you can also do your own Loop to do that as well to get the score. I mean, assuming if Python doesn't have the sum function, how do you do it? Okay, so I'll use this method self that Total score is equal to the sum of all these scores in the scores list Okay, that is pretty much it will actually self That's gorgeous. Okay. So that is the total score And then the only thing is that if I do this I had to you know, Recalculate every time when I call this function Right, so may not be the best option, but for now we'll just see that it's kind of it is working first Okay, the average score will be the same thing. I need to calculate the average How do you get the average score? Yeah, pretty simple, right? It's the average is basically the sum of all the numbers divided by the Quantity of the numbers. So if you know the sum of all this one two three Divide that by what the size of that so the length of the One two three right will give you the average All right, so we'll do that what it do a Self that average score is equal to the self made the sum of the self that scores list Divide that by the length of the self that scores Okay, that will give you the average and then we assign the average to the self average and then also we return that right back Again, it's not the most efficient Why is because every time we get a total call you have to recalculate every time and Usually, you know, you might want to do a different a different approach And I'll show you in a minute So let's say that we get that done and we're gonna create a student object So let's clear our console over here and let's run this thing Okay, so we got a student object if you type in student that get name Okay, we have no name assigned so that's okay because it was initially set to none But let's get the scores student That scores is it a scores list It's also empty because we never include any right, so it's working. We know for sure Let's add some score to this list. See if this add score actually works, right? So student as or Gonna pass in let's say a 100 score for that one and We can verify that make sure the score is actually there so we can see that it is working Let's add another one. Okay, but add a 90 add another one and 95 So now we have three scores in this list. Great. It only has some numbers to play with. Let's get the total in the average Total score Okay, you can see that zero because why we have never calculated yet So in order to get the total score we have to call the function, right? So the student that get total score and we call that function It's going to process that at the same time return the value back so now the student that score is now set updated and It should be 285 if you call that variable directly like this so we just confirmed that the function did work and We did update the total score. What will the average same idea a student that AVG score Is going to be zero But now let's go ahead and update that function call that function cost student that Get average score and It returns the average as well as updated the average score and there you go Okay, so now it's working and then what we need to do is Update this a little bit. I mean, this will work the way it is But again, it's not the most efficient because Every time when I call this function, okay Notice that it goes in here and re-calculate again and again and again Right. The only thing that you need to calculate is if you have a new set of scores If you updated your scores and the number changes then it only then should you update the scores Otherwise you should not update it. So how do you make this better? Well, you realize that when I add the score I add a new one to the score I append it to the scores list. So when that happens that you need to get the average Calculate the average and calculate the total, right? So instead of getting the average getting total, you will create additional function to do that So here would be what we call these helper functions Or helper methods. Okay, they're not called the getter or setter In a way, it's like a setter but it's calculating. So you put here you can say update You know scores or something like that. Okay And what I'm doing is you can say update average update total it doesn't matter But I'll just do one so it would do both. Okay. So in here, what do we do? We're going to do Basically copy this Okay, well, I should move that put it in here And then move this Put it in here And then you can see that now my get it and setter follows the rule of Get it and setter. I'm just returning the actual data back by update the score Okay, so when I add a new score I add that to the list right after that. I'm going to call the self that update score To update the scores. Okay. So every time we add a new score to The object it will calculate right away Okay So let's see that it this works. Okay, I'm going to go and save Run it again. So notice that it did update everything already because initially my list is zero Right, so I have no data if I do student dot You know, I get um Or just type in scores it's zero. Let's update this to include some default values. I'm just going to put here 10 Let's put 100 and then 95 and then 90. Okay three default values and let's run this again Okay, now I have some data student Scores so here is my list Now my total should still be zero zero. Okay my total in average speeds to zero because I haven't invoked the function yet So if you do student dot get um, you know total score Yeah If I call that function I get a zero because I never invoke This function yet to do the calculation so Right now everything is zero. So how do you update it? Well, you have to manually invoke that student dot update score first right Once you've done that then you're going to see that now the student score is now updated As well as the average Okay Get average score Okay, so good So the idea is once you invoke or create this student object Whether you have any data or not You know, you should invoke this function right away So that means inside the initial function or the constructor After I set all these values I want to go ahead and invoke the self dot update score Okay So this will only run one time. All right, just the initial time when you create the object Why do you call it woman because I might pass in some data? I might not pass anything. So you want to call it right away? And you always check to see if there is anything or not. So for example before I call it, what if it's empty like this? I don't want to keep calling every time right when we credit you can also check you say if the Lend of the score we can say if score If that is true Then go ahead and update Now notice I did not have to check the size of the length because if you check using the if statements here Scores if it's zero or empty or none or false then this will be set to You know the false value if it's not Other than that then it'll be true. So in this case, it will be false All right. So if it's not empty Then go ahead and update this if that If it's confusing you can do this if the Lend of the list Okay is greater than zero All right If it's greater than zero Go ahead and call the function. So if I do that now you see that it didn't call. How do we know it's called? print something right print Just some stars. So, you know that it's it's calling the function by the way So you see if I save it I instantiate the object Nothing gets printed Okay, nothing's printed now watch when I put one number in here I run it You see you print the stars because the length is greater than that Go ahead and update the scores right now right now my student That scores is now updated and all the things are updated my average, you know, it's already there There will be one and so forth So that's what you want to do You call it one time when you initialize it if the score is not empty, okay And then you call it one time when you add new scores to that list What if I ask you to delete some of these scores, right? If you delete it you have to update the score every time But when you do a gather you don't have to do that. I'm just returning the data Okay, so that is How you would solve this problem and so Initially it'll be blank. You can also pass in some lists here. So I put here my name is christian and then my data would be 100 100 and then 90 And I got an 80 score on the last one. Okay. So here we go boom and my data Get total score That's total animal student dot get average score. There you go So that is one of the ways how you can solve this problem. Thank you