00:01
Good day, ladies and gentlemen.
00:05
So we are currently looking at problem number 7 .1 in the python, the great python book.
00:14
And it is asking us to create a rectangle class.
00:21
Now, this class should, oops, sorry, should include the following.
00:27
It should include two data fields with one.
00:31
Width and height.
00:34
The constructor should construct a rectangle with the specified width.
00:39
The initial value here should be one for the width and height should be two.
00:48
The method should have a, it should have a method named get area, which returns the area of the rectangle, and similarly a method named get perimeter, which returns the perimeter of the rectangle.
01:07
Okay, without much more ado, let's begin on the question.
01:13
So, okay, so first off to create the rectangle class, we have to do, as we start with, by naming a class, taking class, and naming it rectangle.
01:31
Okay.
01:33
And since this is a, father class, if you will, or a parent class.
01:38
We don't need any thing there.
01:41
So it's just a class.
01:43
And now as a normal when you, when you, when you start a class, you want to do your, you want to have your initializer here.
01:55
And you should have self.
01:58
The variables we want with, of course, is one.
02:03
And this, this setting the width equal to one here, or sets the initial value, if you will, of width be one.
02:15
And similarly, we do the same thing with the height.
02:18
We set it to be two.
02:21
Okay.
02:23
And now it says that the fields, the data fields should be, which should be with, of course, should be equal to the width.
02:35
And similarly, we do the same with the height.
02:43
To height.
02:44
And we only have those two data fields.
02:48
Okay.
02:49
And now we want to do, oops, i'm sorry.
02:52
I forgot to do, i forgot this again, d .e .f.
02:55
I forgot to take the definition here or define it.
02:59
Sorry about that.
03:04
Wait.
03:06
Okay, good.
03:07
Just got to check the alignment on that stuff.
03:09
You know how those things are.
03:11
Python's very particular about it's making sure everything's aligned.
03:19
Okay, so, right.
03:22
Okay, and now we want to have a method called get area.
03:30
Okay, and get area here just has itself.
03:37
It has no...
03:39
So get area then should return the area.
03:45
Of course, the area is just the width times the height.
03:53
So we just...
03:55
And so this self -dot -width then points to the width the width variable, and south dot height points to the height variable.
04:09
So this will return then the two numbers times each other.
04:16
So it should, it will see, return the proper value, the width times the height.
04:22
Okay.
04:23
And then the other one, of course, we want is the get perimeter.
04:32
And again, we just want self.
04:36
And this time we want to return.
04:40
The height, two times the height, or two times the width, i'm sorry, two times the width, plus two times the height in.
04:55
So remember, so the self -got height, again, is referring to the height.
05:02
And he doesn't specifically ask for it, but it's probably just as well.
05:07
You could just do the two more get methods, which would be.
05:11
The get height.
05:17
And like i said, he doesn't really ask for this.
05:20
So there's no, it's not even asked for, but let's see.
05:26
It should be return height equals to, or sorry, self height.
05:44
So that will just return the height of it.
05:50
And i guess technically you don't even need this because they're not private, so you don't actually need to return them, i suppose.
06:01
I guess we could just, yeah, well, i'll include it.
06:04
But technically, you don't have to because the, what you can call it, since the variables aren't, since we didn't declare them as private.
06:18
It we don't really need to include these get now get ones but now that i'm typing on my might as well just continue the typing them i guess so yeah so you don't really have to include them okay so that's the that's the that's the definition of the class okay oops okay and now to do the test function we want to do is we want to do is we to actually do the test here...