1 00:00:00,420 --> 00:00:07,320 Work on this very important lecture and this lecture you learn how to make your script interact with 2 00:00:07,320 --> 00:00:15,320 the user and the user is someone who you can give your adult program and they can execute it easily. 3 00:00:15,390 --> 00:00:22,070 This is done by integrating some code that makes possible interaction with the user. 4 00:00:22,080 --> 00:00:27,070 So in this lecture I'll teach you how to receive user input for your program. 5 00:00:27,070 --> 00:00:30,250 Another program can process these user input. 6 00:00:30,480 --> 00:00:33,030 So let's build a simple function here. 7 00:00:33,300 --> 00:00:35,540 Let's say Miles to kilometers. 8 00:00:35,610 --> 00:00:42,570 This function will get Mols as input and that it will convert this Miles to kilometers. 9 00:00:42,660 --> 00:00:52,710 So Miles is a parameter and I know that one kilometer is equal to 1.6 zero or nine three 4 miles. 10 00:00:52,950 --> 00:01:00,950 So we multiply miles with that number about what we want to do with the altitude is printed out on screen. 11 00:01:01,320 --> 00:01:04,770 So print a kilometer variable. 12 00:01:04,890 --> 00:01:09,320 Now let's call a function the way we are used to. 13 00:01:09,820 --> 00:01:16,440 So so kilometer and we pass an argument here and we get an output. 14 00:01:16,440 --> 00:01:24,780 However a better way to call the function to generate an output would be to integrate an input function 15 00:01:25,080 --> 00:01:26,550 inside the script. 16 00:01:26,550 --> 00:01:32,530 So the input function is a function that implements user interaction feature. 17 00:01:32,610 --> 00:01:39,590 So the idea is the input function will also allow the user to enter some input and it will give input 18 00:01:39,610 --> 00:01:44,600 entered by the user to pass it as an argument to the function. 19 00:01:44,610 --> 00:01:50,890 So this is the idea we want to store the input that will be entered by the user in a variable. 20 00:01:51,030 --> 00:02:01,020 So lets say M which stands for miles to be equal to the input function the input function takes an argument 21 00:02:01,290 --> 00:02:04,850 which is the message that you want to show to the user. 22 00:02:04,890 --> 00:02:11,900 So lets say they use and 2 miles and put a call of there to give it a nice Fluke and that's it. 23 00:02:12,150 --> 00:02:18,780 And then what we want to do with this variable is pass the test and argument to the Massud kilometer 24 00:02:18,810 --> 00:02:19,990 function. 25 00:02:20,070 --> 00:02:26,340 So we just go ahead and call the function here and pass the variable as an argument. 26 00:02:26,370 --> 00:02:31,480 So if I said lets go ahead and around this program now. 27 00:02:31,860 --> 00:02:36,580 So the program is also going to add a value for the Miles. 28 00:02:36,690 --> 00:02:39,410 Go ahead and type in 100 here. 29 00:02:40,370 --> 00:02:44,160 And press enter and we get an error. 30 00:02:45,120 --> 00:02:46,920 So why do we get an error. 31 00:02:47,070 --> 00:02:54,840 We're getting an error because Python is trying to multiply a string with a fourth number. 32 00:02:54,840 --> 00:02:58,410 So we enter 100 which is seemingly a number. 33 00:02:58,650 --> 00:03:04,810 But however the input function reads everything that you pass to be treated as a string. 34 00:03:04,980 --> 00:03:12,000 So in this case it gets a Number One hundred and converts to two string and it passes to the function. 35 00:03:12,000 --> 00:03:13,920 So that's why we get an error. 36 00:03:13,980 --> 00:03:21,460 So we want to convert this given input from the user from a string to a float type to do that. 37 00:03:21,510 --> 00:03:32,780 You just go ahead and type M equals float and so what this does is it just gets current value of converts 38 00:03:32,810 --> 00:03:35,090 to flawed data. 39 00:03:35,330 --> 00:03:37,960 Now let's go ahead and run the program. 40 00:03:38,410 --> 00:03:39,250 OK. 41 00:03:39,610 --> 00:03:45,170 We are asked to any of the models let's say 100 and we get the output. 42 00:03:45,200 --> 00:03:52,510 So the Z idea of the user interaction the program asks the user to enter in both valid as input and 43 00:03:52,510 --> 00:03:53,680 then is the output. 44 00:03:53,870 --> 00:03:56,510 Now we can publish the program even more. 45 00:03:56,570 --> 00:04:01,990 We can print out a kilometer stream beside the value just like this. 46 00:04:01,990 --> 00:04:04,710 So we add a call and a string. 47 00:04:05,120 --> 00:04:12,350 So the print function that we print out to values if we execute the program again and or some models 48 00:04:13,230 --> 00:04:21,050 and error escapes you get the value and I'll label one last thing I want to show it to you is that you 49 00:04:21,050 --> 00:04:25,040 don't have to use slider for executing a program. 50 00:04:25,040 --> 00:04:29,760 You can also execute a program using your command line to do that. 51 00:04:29,960 --> 00:04:35,340 You should type the program which you want to exit the program with hogi. 52 00:04:35,340 --> 00:04:43,600 So the program is Python have a python program you want to execute is adopt twice creep. 53 00:04:43,740 --> 00:04:51,280 So you enter the path of your data by script and press enter. 54 00:04:51,460 --> 00:04:58,340 Now Vanesa user you just follow the instructions of a program and you finally get the ultimate. 55 00:04:58,760 --> 00:05:05,360 So that's how you can interact with the user and get the user input and processing in your programs. 56 00:05:05,510 --> 00:05:06,570 Talk to me in the next lecture.