1 00:00:00,752 --> 00:00:02,130 [Instructor] - In this self check exercise, 2 00:00:02,130 --> 00:00:05,470 we'd like you to study once again the try it function 3 00:00:05,470 --> 00:00:08,260 to figure out what's going to be displayed 4 00:00:08,260 --> 00:00:11,920 when this function gets called with the value 10.7 5 00:00:11,920 --> 00:00:15,420 which is a floating point number and the string, Python. 6 00:00:15,420 --> 00:00:17,040 So go ahead and pause the video 7 00:00:17,040 --> 00:00:18,580 and think about that for a moment, 8 00:00:18,580 --> 00:00:20,283 then come back to see the answer. 9 00:00:24,210 --> 00:00:27,090 Okay, let's take a look at this function definition. 10 00:00:27,090 --> 00:00:31,840 So if we pass the float value 10.7 into this function, 11 00:00:31,840 --> 00:00:34,460 here we're going to try to convert that float value 12 00:00:34,460 --> 00:00:36,330 into an integer, which will work 13 00:00:36,330 --> 00:00:38,460 and truncate the floating point part. 14 00:00:38,460 --> 00:00:40,650 So X will become the value ten. 15 00:00:40,650 --> 00:00:42,560 Because this executes successfully, 16 00:00:42,560 --> 00:00:45,470 the except clause would be skipped, the else clause 17 00:00:45,470 --> 00:00:48,900 however will print that the integer representation 18 00:00:48,900 --> 00:00:53,900 of 10.7 is ten and then the finally clause will execute. 19 00:00:54,100 --> 00:00:55,870 So let's stop there for a moment. 20 00:00:55,870 --> 00:00:58,720 We'll define the function here in our first snippet, 21 00:00:58,720 --> 00:01:01,920 and let's execute the call with 10.7 22 00:01:01,920 --> 00:01:04,960 to confirm the two things that will be displayed. 23 00:01:04,960 --> 00:01:08,770 Remember, the finally clause is always going to execute 24 00:01:08,770 --> 00:01:13,230 if the flow of control entered the corresponding try suite. 25 00:01:13,230 --> 00:01:15,830 So that confirms that here as well. 26 00:01:15,830 --> 00:01:19,750 Now going back up above, if we call with the string Python, 27 00:01:19,750 --> 00:01:21,630 of course this try suite's statement 28 00:01:23,100 --> 00:01:25,940 will cause a value error exception. 29 00:01:25,940 --> 00:01:27,810 So the try suite will terminate 30 00:01:27,810 --> 00:01:30,440 and will jump immediately to the except clause. 31 00:01:30,440 --> 00:01:32,350 In this case, it will print out 32 00:01:32,350 --> 00:01:35,210 'Python could not be converted to an integer.' 33 00:01:35,210 --> 00:01:37,240 The else clause will not execute 34 00:01:37,240 --> 00:01:40,500 because the try suite did not complete successfully 35 00:01:40,500 --> 00:01:43,240 but the finally clause will always execute. 36 00:01:43,240 --> 00:01:45,960 So we'll get the except clause's print statement 37 00:01:45,960 --> 00:01:47,800 and the finally clause's print statement 38 00:01:47,800 --> 00:01:50,330 in this case, and just to confirm that, 39 00:01:50,330 --> 00:01:52,863 you can see that is indeed the case.