Welcome back.
We finished the predict mileage function.
Now let's create another function that validates the features range.
Think about if the user enters number of cylinders like for example 12.
And your data set is programmed and uh and the range is between 3 and 9 cylinders.
This is out of range.
So we need to validate the features.
We need to allow the user to enter uh cylinders between 3 and 8.
Displacement between 68 and 45 455.
Horsepower between 46 and uh, 230, and so on.
Okay, in order to do that, we need to create a new function here.
Let's name it as validate features.
Takes car feature object and returns a validation result object.
This is a data class that we created before called validate results in the car features.
So let me correct the name validate results and Alt plus enter to import this data class.
Okay.
So it takes a car features instance and returns a data class validate results instance.
Okay start with val errors.
Mutable list of strings.
Name it errors.
And let's check every feature.
If there is any error in any feature, it will be added to the errors.
Mutable list.
Okay, so this is the logic behind this.
So if car features dot slender, if it is not in three cylinders to eight cylinders, then go and add
to the errors list.
This line cylinders must be between 3 and eight.
So guys again it's very clear.
Okay.
Car features, not cylinders.
If the added number of cylinders is not between 3 and 8.
Go and add to the errors.
Mutable list.
This line of code cylinders must be between 3 and 8.
Okay, so another check if car features dot displacement.
It's not in 68 F to 455 F.
Then what we need to do errors.
Displacement should be added between 68 and 455.
Okay, let me continue with car features.
The horsepower.
This is for horsepower.
The weight between this number.
Then errors must be added.
The weight acceleration.
If it is not in eight f, 25 F, if not the model year, it's not between 70 and 82.
The model year between 82.
Okay.
This is the validation.
This is the validation result.
Okay.
Now we need to return a validation result object.
Having this valid errors is empty.
And errors.
Errors if it is not are not having any errors.
Go and set the valid to true.
So I'm checking if errors list is is empty.
So if this errors list is empty go and return is valid true.
Otherwise go and return the errors.
Okay, this is the idea behind this function.
Validate features.
We're going to use it in the next videos in order to ensure that our codes are are, um, are working
fine and we don't enter any, uh, unacceptable and out of range inputs.