00:02
We are going to create a python program that computes students average.
00:09
The user will input the following information regarding the student name, math, signs and english grades.
00:21
Then we create a class called students.
00:25
We use the unit function to collect the student information, that is the name, and the grades, create a function that will perform the computation of a function.
00:35
Of the average and then create a function that will display the result.
00:40
So let's say that the student class will have as properties, name, math, science, and english grades.
00:55
So we have a string corresponding to the name of the student and three numbers corresponding to the grades in these three areas.
01:09
And then we have two methods, this one here, to calculate the average, another one to display the results.
01:18
And we have also a constructor that is a function underscore -un -un -un -un -un -score -un -un -score, which collects the information at the moment of creation of an object of type students.
01:39
Create the object, the corresponding object.
01:42
So here we have the students that by students that by file as indicated over here contains the class students as we see in 9 -1.
02:02
So we have first a constructor as we said is the function underscore underscore in it underscore underscore and because we are creating a class first argument solve itself.
02:14
Which corresponds to the object that is current or created at the moment, the instance of the object of the class.
02:26
And we have the arguments correspond to the data we are going to collect from the user.
02:36
That is named, math grade, science grade, and english grade.
02:40
In this case, we give default bodies for those parameters.
02:48
In the cases of name, we give the stream unknown and for the grades we give the value zero.
02:56
Then inside this constructor or unit function, we established the properties of the object.
03:05
That's why we use self to indicate that.
03:10
And we established the value, set the values for those properties of the object equal to the corresponding argument.
03:18
For example self, that name is the property name with the capital n of the object and it is initialized to the value name pass as argument here.
03:32
If there is no corresponding name, then it's not passed as argument, then name will be unknown.
03:42
And similarly, we have the property math grades with capital m, capital g, and that variable is that property of the object is set to its argument math grade.
04:00
And similarly with the other two grades.
04:03
And finally, we set the average as a property of the object to zero.
04:08
That is, when we create an object, and automatically it has an average zero until we calculated true average.
04:17
We could have, of course, calculate the average here.
04:22
Directly because we are assigning the values of these three variables.
04:25
But we let us keep as simple as possible.
04:31
Then we have the method that calculates the average.
04:35
And that method set the property average with capital a of the object here to the mathematical expression corresponding to the average.
04:49
And we see that we use the properties of the object that are set either at the moment of creation of the object or after that by assigning the properties directly on a main program for example and then we have the sum of the three grades and divided by three which is the number of grades we have here that's the only thing the function calculated average does and you can see we don't have to return anything because the result of the average is a property of the object as we created over here in the constructor.
05:30
So there is only that line of calculation.
05:34
Then we print out the information regarding the student that is its name and is great by using the function print and that's why we use the underscore underscore ostr underscore function which is useful in the sense that we can print the object and and when we say print, that is the same common used to print numbers of strings.
06:02
That command will print this information will return here as a text.
06:07
So we create the text basically with combinating the name of the student and the grades with certain format here, tabulations, and fixed number of integers.
06:26
Before the period and then after the period we can see only two decimals.
06:32
That's a way to format the output.
06:38
And there is here an important fact is that we calculate the average just before we print out the information regarding the average.
06:51
And we do that by calling the function of the object, the method calculate average here.
06:57
And as you can see, because that's a method of the object, we got to use self -property.
07:06
And when we construct the string, text out, we return that text...