All right, it's exercise time, let's combine everything that we've learned into this challenge, what
I want you to do is to create a function called the highest even.
And this function is going to take a list, data type and this function for now, we'll just pass.
But I want you to fill in this part with whatever you think is going to allow us to achieve this.
If I do print highest even and I give it a list of, let's say one, two, three, four, eight.
I want the highest even to be printed in this list and actually let's do 10 here.
So the highest even number in this list is 10.
Just for fun, let's at 11 as well, so the answer should be printed here as 10.
So based on everything you've learned so far, try to fill this part so that you create your own function
highest even pause the video here, give it a try.
Otherwise, I'm going to go with the answer.
So what I want to do here, let's think about this, is I want to make sure that, first of all, we
only consider the numbers that are even in here.
So maybe what I'll do is create a new list called Evans, and Evans is going to be an empty list for
now, but I'm going to populate this with all of the.
Even numbers, so I'm going to remove three and 11 from this.
So let's do that.
I'm going to say for item in ELLI.
If Eitam.
Modulo two.
Equals zero, which means it's going to be even.
Then I'm going to even.
Append the item, so I'm going to add it to this new list.
And then finally in here, once we have the even's list, I want to find the highest number.
Now you can do this manually and go through it one by one, or Python comes with a nice function called
Max.
And as you can see, we give it an iterable and it'll tell us what the max number is.
In our case, we can just give it Even's.
And remember, we want to return something from this function that is what is the highest number?
Well, we want to return whatever the max of the Even's is if I run this.
Awesome, looks like it's working.
Now, some of you may have gotten tricked and tried to return inside of the forum, but if we do this,
remember.
That this still works, but we actually return from the function when we hit our first item.
If we had another item, let's say two in here and I click run.
We get to and why is that?
Because I'm returning when we loop the first time through our item, which will be two, is to an even
number.
Yes, it is.
So we're going to append and then we're finally returning Max Evans, which only contains the item two.
So you want to make sure here that the indentation really matters.
And if you're returning something from inside a loop, you want to make sure that that's your intended
behavior.
You usually want to live through something and then return.
So make sure you don't prematurely exit the loop.
Nice and simple.
Remember, your answer may be different than mine.
There are many ways to go about this, but hopefully by practicing this, you have a better idea of
functions.
We now have a great utility function, highest even that we can use all over our program.
Good job getting this far and I'll see you in the next one.