WEBVTT

00:00.080 --> 00:00.920
Welcome back.

00:00.960 --> 00:03.680
We finished the predict mileage function.

00:03.720 --> 00:09.960
Now let's create another function that validates the features range.

00:10.200 --> 00:16.720
Think about if the user enters number of cylinders like for example 12.

00:16.880 --> 00:25.800
And your data set is programmed and uh and the range is between 3 and 9 cylinders.

00:26.040 --> 00:27.640
This is out of range.

00:27.640 --> 00:30.720
So we need to validate the features.

00:30.720 --> 00:36.120
We need to allow the user to enter uh cylinders between 3 and 8.

00:36.160 --> 00:40.680
Displacement between 68 and 45 455.

00:41.000 --> 00:46.400
Horsepower between 46 and uh, 230, and so on.

00:46.440 --> 00:52.360
Okay, in order to do that, we need to create a new function here.

00:52.480 --> 00:56.920
Let's name it as validate features.

00:56.920 --> 01:04.600
Takes car feature object and returns a validation result object.

01:04.640 --> 01:11.420
This is a data class that we created before called validate results in the car features.

01:11.580 --> 01:19.420
So let me correct the name validate results and Alt plus enter to import this data class.

01:19.460 --> 01:19.940
Okay.

01:20.260 --> 01:29.140
So it takes a car features instance and returns a data class validate results instance.

01:29.180 --> 01:32.940
Okay start with val errors.

01:32.980 --> 01:36.900
Mutable list of strings.

01:36.940 --> 01:38.060
Name it errors.

01:38.060 --> 01:41.380
And let's check every feature.

01:41.380 --> 01:46.300
If there is any error in any feature, it will be added to the errors.

01:46.300 --> 01:47.580
Mutable list.

01:47.620 --> 01:51.140
Okay, so this is the logic behind this.

01:51.420 --> 02:02.340
So if car features dot slender, if it is not in three cylinders to eight cylinders, then go and add

02:02.380 --> 02:04.380
to the errors list.

02:04.540 --> 02:09.930
This line cylinders must be between 3 and eight.

02:10.130 --> 02:12.650
So guys again it's very clear.

02:12.690 --> 02:13.250
Okay.

02:13.290 --> 02:15.250
Car features, not cylinders.

02:15.250 --> 02:19.610
If the added number of cylinders is not between 3 and 8.

02:19.770 --> 02:21.930
Go and add to the errors.

02:21.930 --> 02:23.010
Mutable list.

02:23.290 --> 02:28.370
This line of code cylinders must be between 3 and 8.

02:28.410 --> 02:35.130
Okay, so another check if car features dot displacement.

02:35.170 --> 02:42.650
It's not in 68 F to 455 F.

02:42.850 --> 02:45.290
Then what we need to do errors.

02:45.290 --> 02:51.210
Displacement should be added between 68 and 455.

02:51.250 --> 02:55.090
Okay, let me continue with car features.

02:55.130 --> 02:56.730
The horsepower.

02:56.770 --> 02:58.530
This is for horsepower.

02:58.810 --> 03:02.130
The weight between this number.

03:02.330 --> 03:04.970
Then errors must be added.

03:04.970 --> 03:07.090
The weight acceleration.

03:07.130 --> 03:15.830
If it is not in eight f, 25 F, if not the model year, it's not between 70 and 82.

03:15.870 --> 03:17.670
The model year between 82.

03:17.910 --> 03:18.390
Okay.

03:18.630 --> 03:21.110
This is the validation.

03:21.150 --> 03:24.230
This is the validation result.

03:24.430 --> 03:24.870
Okay.

03:25.190 --> 03:29.150
Now we need to return a validation result object.

03:29.310 --> 03:31.710
Having this valid errors is empty.

03:31.710 --> 03:32.550
And errors.

03:32.590 --> 03:37.910
Errors if it is not are not having any errors.

03:37.950 --> 03:41.070
Go and set the valid to true.

03:41.230 --> 03:44.790
So I'm checking if errors list is is empty.

03:45.070 --> 03:50.950
So if this errors list is empty go and return is valid true.

03:50.990 --> 03:53.790
Otherwise go and return the errors.

03:53.830 --> 03:57.430
Okay, this is the idea behind this function.

03:57.430 --> 03:59.030
Validate features.

03:59.030 --> 04:09.070
We're going to use it in the next videos in order to ensure that our codes are are, um, are working

04:09.110 --> 04:16.790
fine and we don't enter any, uh, unacceptable and out of range inputs.
