1 00:00:00,550 --> 00:00:02,100 - [Instructor] In this self-check exercise, 2 00:00:02,100 --> 00:00:05,400 I'd like you to take a look at the try it function 3 00:00:05,400 --> 00:00:09,560 and figure out before you execute the code down below 4 00:00:09,560 --> 00:00:14,560 what is going to be displayed if we pass this function 10.7 5 00:00:14,930 --> 00:00:16,630 and what is going to be displayed 6 00:00:16,630 --> 00:00:19,600 if we pass this function, the string Python. 7 00:00:19,600 --> 00:00:21,530 So, just to show you down below here, 8 00:00:21,530 --> 00:00:23,480 we're going to define the same function 9 00:00:23,480 --> 00:00:24,430 that you see here, 10 00:00:24,430 --> 00:00:25,730 and then, we're going to call it 11 00:00:25,730 --> 00:00:27,140 with those two values. 12 00:00:27,140 --> 00:00:29,800 So, pause the video and think about that for a moment, 13 00:00:29,800 --> 00:00:31,733 and then come back to see the answer. 14 00:00:36,650 --> 00:00:39,180 Okay, let's go ahead and define the function, 15 00:00:39,180 --> 00:00:41,630 and before I execute the next two snippets, 16 00:00:41,630 --> 00:00:43,000 let's talk about this. 17 00:00:43,000 --> 00:00:46,260 So, we're going to first pass in the value 10.7, 18 00:00:46,260 --> 00:00:49,030 which we will receive as the parameter value. 19 00:00:49,030 --> 00:00:52,060 We're going to convert that floating point value 20 00:00:52,060 --> 00:00:53,160 into an integer, 21 00:00:53,160 --> 00:00:56,550 so the value 10 will get assigned to x. 22 00:00:56,550 --> 00:00:59,630 Because that's going to be a valid conversion, 23 00:00:59,630 --> 00:01:01,700 this except clause will be skipped, 24 00:01:01,700 --> 00:01:03,920 and we'll jump down to the else clause 25 00:01:03,920 --> 00:01:06,660 to print that the integer representation 26 00:01:06,660 --> 00:01:08,650 of 10.7 is, 27 00:01:08,650 --> 00:01:10,330 and then we'll display 10. 28 00:01:10,330 --> 00:01:12,930 So, let's go ahead and execute that just to confirm. 29 00:01:13,920 --> 00:01:16,430 And indeed, the integer representation 30 00:01:16,430 --> 00:01:18,600 of 10.7 is 10. 31 00:01:18,600 --> 00:01:20,690 Now, let's talk about the string Python. 32 00:01:20,690 --> 00:01:24,580 So, that string will be assigned to the parameter value. 33 00:01:24,580 --> 00:01:27,610 When we try to convert that to an integer, hell... 34 00:01:27,610 --> 00:01:30,670 or Python, excuse me, is not a valid integer. 35 00:01:30,670 --> 00:01:33,410 So, this will result in a value error. 36 00:01:33,410 --> 00:01:36,150 The try suite will terminate, 37 00:01:36,150 --> 00:01:39,610 so if there were additional statements after this one, 38 00:01:39,610 --> 00:01:41,610 they would not execute. 39 00:01:41,610 --> 00:01:43,900 We'll jump to the first except handler, 40 00:01:43,900 --> 00:01:46,120 which matches the type of exception 41 00:01:46,120 --> 00:01:47,520 that's going to be thrown, 42 00:01:47,520 --> 00:01:49,200 and in that case, we will display 43 00:01:49,200 --> 00:01:52,660 10.7 could not be converted to an integer. 44 00:01:52,660 --> 00:01:55,060 The else clause will not execute, 45 00:01:55,060 --> 00:01:57,060 and the function will terminate. 46 00:01:57,060 --> 00:01:59,160 So, let's just try that to make sure, 47 00:01:59,160 --> 00:02:02,360 and indeed, we get Python could not be converted 48 00:02:02,360 --> 00:02:03,283 to an integer.