1 00:00:00,570 --> 00:00:11,370 Hello and welcome to the 3 and the concluding part to the feed you on this project for creatine a weight 2 00:00:11,400 --> 00:00:14,550 conversion tool in this part. 3 00:00:14,550 --> 00:00:20,610 We are going to create the function that will do the calculation. 4 00:00:20,610 --> 00:00:28,340 So we're going to define the function right at the top of the document here. 5 00:00:28,410 --> 00:00:34,800 Edit Or just underneath this module here is where I will define the function. 6 00:00:34,800 --> 00:00:39,680 So we call the function you define it function by typing in the keyword. 7 00:00:39,750 --> 00:00:41,870 Def followed by the name. 8 00:00:41,860 --> 00:00:43,860 So I'm gonna call it calculate 9 00:00:46,890 --> 00:00:57,610 and inside the argument of the function I'm going to pass it this value. 10 00:00:58,830 --> 00:01:03,340 You use this when you're not sure the number of arguments you're gonna pass through. 11 00:01:03,930 --> 00:01:08,170 So this represents the arguments that will pass through that function. 12 00:01:09,480 --> 00:01:17,700 And when you create a function after the parentheses you put a call on there and then now we'll start 13 00:01:17,790 --> 00:01:22,490 to define the logic for the function to save time. 14 00:01:22,550 --> 00:01:25,340 I've added the logic here. 15 00:01:25,350 --> 00:01:32,610 I'm just going to explain what the bot the bunch of code I've added here means. 16 00:01:32,640 --> 00:01:44,430 So here are defined a calculate procedure which is called either when the user presses the calculate 17 00:01:44,430 --> 00:01:56,790 button or hits the return or enter key what it will to do it will perform the feat to meet his calculation 18 00:01:57,720 --> 00:02:07,620 in the number of feet from our Entry widget and placing the result in our label widget we specified 19 00:02:07,710 --> 00:02:13,440 a tax variable options when we created the widget. 20 00:02:13,650 --> 00:02:21,720 So we the we specified that the global fit variable is variable. 21 00:02:21,720 --> 00:02:26,370 Here we define the variable code feet or meters. 22 00:02:26,520 --> 00:02:27,510 We are global. 23 00:02:27,510 --> 00:02:29,730 So here. 24 00:02:29,730 --> 00:02:34,530 So we defined here you see the global feed variable here. 25 00:02:34,560 --> 00:02:41,090 We are using that here as a text variable here is where we define the global feed variables. 26 00:02:41,090 --> 00:02:42,860 We're using that. 27 00:02:43,300 --> 00:02:45,540 We're using that as the N3. 28 00:02:45,540 --> 00:02:50,150 So that's will be where they'll enter the value in Ft. 29 00:02:50,160 --> 00:02:59,640 So which means at any time this entry changes T.K. will automatically update the global variable code 30 00:02:59,780 --> 00:03:00,320 feet. 31 00:03:00,330 --> 00:03:12,750 Similarly if we explicitly change the value of the text variable that is associated with a widget the 32 00:03:12,750 --> 00:03:19,040 widget will automatically be updated with the current contents of the variable. 33 00:03:19,050 --> 00:03:27,380 So we're also doing the same for the meters global variable which is here. 34 00:03:27,390 --> 00:03:35,550 We're so attached to this label here called text variable meta so the same applies to that. 35 00:03:35,580 --> 00:03:42,910 So here also we've implemented some error handling with the try and accept statements. 36 00:03:43,260 --> 00:03:52,330 So whenever you implement error handling you need to implement a try and an accept statement. 37 00:03:52,470 --> 00:03:58,690 So in the try block here we've got the get method which will get the value in Ft. 38 00:03:58,710 --> 00:04:01,900 And here is this is what gets a conversion. 39 00:04:01,970 --> 00:04:05,940 We're using the set method to set the value in meters. 40 00:04:06,100 --> 00:04:07,430 And this is what he does it. 41 00:04:07,440 --> 00:04:11,070 This is how it does a calculation based on this. 42 00:04:11,070 --> 00:04:22,320 So if we multiply this this by the value that is entered and multiply that by this and add this and 43 00:04:22,320 --> 00:04:28,850 divide by that that will give you the conversion in meters. 44 00:04:29,130 --> 00:04:34,310 And here this is any error that occurs it will capture the arrow there. 45 00:04:34,330 --> 00:04:38,490 Okay so that is basically the application. 46 00:04:38,490 --> 00:04:49,410 And here again this is I've already spoken about this but this here is this tells T.K. to enter its 47 00:04:49,500 --> 00:04:50,990 event loop. 48 00:04:51,000 --> 00:04:54,130 This is needed to make everything wrong. 49 00:04:54,130 --> 00:05:02,490 So this is what keeps the application running by the event looping so let me save that and then we can 50 00:05:02,490 --> 00:05:06,620 test and run our application make sure. 51 00:05:08,700 --> 00:05:13,900 Make sure you format your code properly. 52 00:05:14,220 --> 00:05:16,410 If not the editor would complain. 53 00:05:16,410 --> 00:05:19,140 You can see I've got my code structures. 54 00:05:19,170 --> 00:05:25,440 Make sure you've got yours completely structured the same way if not eat or complain someone would click 55 00:05:25,440 --> 00:05:32,700 on save and run the application by going on run and clicking on run module. 56 00:05:34,060 --> 00:05:34,660 Okay. 57 00:05:34,700 --> 00:05:37,420 So this is our application here. 58 00:05:37,530 --> 00:05:44,540 I'm just going to type in a value say see a 56 click calculate. 59 00:05:44,540 --> 00:05:47,550 I can see this is the equivalent in meters. 60 00:05:47,550 --> 00:05:51,750 So the application is working as designed. 61 00:05:51,900 --> 00:05:54,000 So that's it for this project. 62 00:05:54,000 --> 00:05:55,880 Thanks for watching and bye for now.