1 00:00:00,480 --> 00:00:06,420 All right, it's exercise time, let's combine everything that we've learned into this challenge, what 2 00:00:06,420 --> 00:00:11,040 I want you to do is to create a function called the highest even. 3 00:00:11,820 --> 00:00:19,980 And this function is going to take a list, data type and this function for now, we'll just pass. 4 00:00:20,220 --> 00:00:25,340 But I want you to fill in this part with whatever you think is going to allow us to achieve this. 5 00:00:25,740 --> 00:00:34,920 If I do print highest even and I give it a list of, let's say one, two, three, four, eight. 6 00:00:36,290 --> 00:00:41,560 I want the highest even to be printed in this list and actually let's do 10 here. 7 00:00:42,140 --> 00:00:46,220 So the highest even number in this list is 10. 8 00:00:47,670 --> 00:00:54,480 Just for fun, let's at 11 as well, so the answer should be printed here as 10. 9 00:00:55,450 --> 00:01:01,670 So based on everything you've learned so far, try to fill this part so that you create your own function 10 00:01:01,690 --> 00:01:05,260 highest even pause the video here, give it a try. 11 00:01:05,600 --> 00:01:07,300 Otherwise, I'm going to go with the answer. 12 00:01:08,630 --> 00:01:15,260 So what I want to do here, let's think about this, is I want to make sure that, first of all, we 13 00:01:15,260 --> 00:01:18,770 only consider the numbers that are even in here. 14 00:01:20,140 --> 00:01:28,570 So maybe what I'll do is create a new list called Evans, and Evans is going to be an empty list for 15 00:01:28,570 --> 00:01:32,740 now, but I'm going to populate this with all of the. 16 00:01:33,800 --> 00:01:37,670 Even numbers, so I'm going to remove three and 11 from this. 17 00:01:38,850 --> 00:01:39,930 So let's do that. 18 00:01:39,990 --> 00:01:43,050 I'm going to say for item in ELLI. 19 00:01:44,640 --> 00:01:45,840 If Eitam. 20 00:01:47,360 --> 00:01:48,470 Modulo two. 21 00:01:49,540 --> 00:01:52,120 Equals zero, which means it's going to be even. 22 00:01:53,270 --> 00:01:55,010 Then I'm going to even. 23 00:01:57,050 --> 00:02:01,490 Append the item, so I'm going to add it to this new list. 24 00:02:03,250 --> 00:02:12,360 And then finally in here, once we have the even's list, I want to find the highest number. 25 00:02:12,820 --> 00:02:20,410 Now you can do this manually and go through it one by one, or Python comes with a nice function called 26 00:02:20,530 --> 00:02:21,010 Max. 27 00:02:21,320 --> 00:02:27,160 And as you can see, we give it an iterable and it'll tell us what the max number is. 28 00:02:27,580 --> 00:02:30,100 In our case, we can just give it Even's. 29 00:02:31,320 --> 00:02:37,380 And remember, we want to return something from this function that is what is the highest number? 30 00:02:37,560 --> 00:02:42,900 Well, we want to return whatever the max of the Even's is if I run this. 31 00:02:47,310 --> 00:02:48,990 Awesome, looks like it's working. 32 00:02:50,260 --> 00:02:57,790 Now, some of you may have gotten tricked and tried to return inside of the forum, but if we do this, 33 00:02:57,940 --> 00:02:58,600 remember. 34 00:02:59,800 --> 00:03:06,830 That this still works, but we actually return from the function when we hit our first item. 35 00:03:07,210 --> 00:03:12,640 If we had another item, let's say two in here and I click run. 36 00:03:13,990 --> 00:03:16,720 We get to and why is that? 37 00:03:16,960 --> 00:03:24,730 Because I'm returning when we loop the first time through our item, which will be two, is to an even 38 00:03:24,730 --> 00:03:25,140 number. 39 00:03:25,180 --> 00:03:25,730 Yes, it is. 40 00:03:25,750 --> 00:03:33,610 So we're going to append and then we're finally returning Max Evans, which only contains the item two. 41 00:03:34,030 --> 00:03:37,660 So you want to make sure here that the indentation really matters. 42 00:03:37,660 --> 00:03:44,350 And if you're returning something from inside a loop, you want to make sure that that's your intended 43 00:03:44,350 --> 00:03:45,010 behavior. 44 00:03:45,460 --> 00:03:48,800 You usually want to live through something and then return. 45 00:03:49,660 --> 00:03:52,840 So make sure you don't prematurely exit the loop. 46 00:03:53,880 --> 00:03:54,930 Nice and simple. 47 00:03:55,410 --> 00:03:58,690 Remember, your answer may be different than mine. 48 00:03:59,220 --> 00:04:06,000 There are many ways to go about this, but hopefully by practicing this, you have a better idea of 49 00:04:06,000 --> 00:04:06,600 functions. 50 00:04:06,750 --> 00:04:13,080 We now have a great utility function, highest even that we can use all over our program. 51 00:04:14,330 --> 00:04:16,790 Good job getting this far and I'll see you in the next one.