Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,570 --> 00:00:01,020
All right.
2
00:00:01,030 --> 00:00:02,400
It's exercise time.
3
00:00:02,410 --> 00:00:06,190
Let's combine everything that we've learned into this challenge.
4
00:00:06,250 --> 00:00:13,570
What I want you to do is to create a function called the highest even and this function is going to
5
00:00:13,570 --> 00:00:15,940
take a list data.
6
00:00:16,780 --> 00:00:20,190
And this function for now we'll just pass.
7
00:00:20,290 --> 00:00:25,800
But I want you to fill in this part with whatever you think is going to allow us to achieve this.
8
00:00:25,840 --> 00:00:38,500
If I do print highest even and I give it a list of let's say 1 2 3 4 8 I want the highest even to be
9
00:00:38,500 --> 00:00:40,060
printed in this list.
10
00:00:40,060 --> 00:00:42,140
And actually let's do 10 here.
11
00:00:42,220 --> 00:00:48,240
So the highest even number in this list is 10 just for fun.
12
00:00:48,240 --> 00:00:50,370
That's at eleven as well.
13
00:00:50,430 --> 00:00:58,200
So the answer should be printed here as 10 so based on everything you've learned so far.
14
00:00:58,210 --> 00:01:01,720
Try to fill this part so that you create your own function.
15
00:01:01,730 --> 00:01:04,420
Hi Stephen pause the video here.
16
00:01:04,420 --> 00:01:08,660
Give it a try otherwise I'm going to go with the answer.
17
00:01:08,700 --> 00:01:10,290
So what I want to do here.
18
00:01:10,350 --> 00:01:17,640
Let's think about this is I want to make sure that first of all we only consider the numbers that are
19
00:01:17,850 --> 00:01:27,890
even in here so maybe what I'll do is create a new list called evens and events is going to be an empty
20
00:01:27,890 --> 00:01:36,180
list for now but I'm going to populate this with all of the even numbers so I'm going to remove three
21
00:01:36,180 --> 00:01:40,090
and 11 from this so let's do that.
22
00:01:40,090 --> 00:01:53,500
I'm going to say for item in ally if item modulo 2 equals zero which means it's going to be even then
23
00:01:53,500 --> 00:01:59,110
I'm going to even append the item.
24
00:01:59,110 --> 00:02:03,120
So I'm going to add it to this new list.
25
00:02:03,350 --> 00:02:12,850
And then finally in here once we have the Evens list I want to find the highest number.
26
00:02:12,890 --> 00:02:20,390
Now you can do this manually and go through it one by one or Python comes with a nice function called
27
00:02:20,600 --> 00:02:21,410
Max.
28
00:02:21,410 --> 00:02:28,400
And as you can see we give it an interval and it'll tell us what the max number is in our case we can
29
00:02:28,400 --> 00:02:34,680
just give it evens and remember we want to return something from this function.
30
00:02:34,800 --> 00:02:37,620
That is what is the highest number.
31
00:02:37,650 --> 00:02:41,750
Well we want to return whatever the max of the Evens is.
32
00:02:42,030 --> 00:02:50,220
If I run this I get 10 awesome looks like it's working.
33
00:02:50,320 --> 00:02:56,230
Now some of you may have gotten tricked and tried to return inside of the four.
34
00:02:56,770 --> 00:03:05,830
But if we do this remember that this still works but we actually return from the function when we hit
35
00:03:05,860 --> 00:03:07,210
our first item.
36
00:03:07,300 --> 00:03:17,000
If we had another item let's say two in here and I click Run we get two and why is that.
37
00:03:17,000 --> 00:03:25,210
Because I'm returning when we loop the first time through our item which will be two is to an even number.
38
00:03:25,220 --> 00:03:25,760
Yes it is.
39
00:03:25,760 --> 00:03:34,050
So we're going to append and then we're finally returning Max evens which only contains the item two.
40
00:03:34,100 --> 00:03:39,410
So you want to make sure here that the indentation really matters and if you're returning something
41
00:03:39,650 --> 00:03:45,410
from inside a loop you want to make sure that that's your intended behavior.
42
00:03:45,530 --> 00:03:49,630
You usually want to loop through something and then return.
43
00:03:49,730 --> 00:03:55,450
So make sure you don't prematurely exit the loop nice and simple.
44
00:03:55,450 --> 00:03:59,250
Remember your answer may be different than mine.
45
00:03:59,290 --> 00:04:06,820
There are many ways to go about this but hopefully by practicing this you have a better idea of functions.
46
00:04:06,820 --> 00:04:14,330
We now have a great utility function highest even that we can use all over our program.
47
00:04:14,390 --> 00:04:17,690
Good job getting this far and I'll see you in the next one up.
4800
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.