1 00:00:00,250 --> 00:00:01,509 Welcome back to the 2 00:00:01,740 --> 00:00:05,710 last time we successfully created, created our very own custom module 3 00:00:06,000 --> 00:00:10,270 and we were able to import and make use of it in our main file. 4 00:00:10,420 --> 00:00:13,550 But now I want to show you how we can import 5 00:00:13,560 --> 00:00:17,829 some of the standard libraries and modules that comes with Python. 6 00:00:18,079 --> 00:00:22,309 So let me go ahead and remove all of this code. And I'm going to leave the keyword, 7 00:00:22,760 --> 00:00:24,530 import the main function 8 00:00:25,030 --> 00:00:30,110 and the name of the module we're going to import is called random. 9 00:00:30,469 --> 00:00:34,680 This is an inbuilt module within Python 10 00:00:34,810 --> 00:00:41,369 that would allow us to make or generate random numbers from a sequence. In fact, 11 00:00:41,619 --> 00:00:44,569 let me show you a bit of the documentation in here. 12 00:00:45,080 --> 00:00:48,090 You can see Python has a built in module called random. 13 00:00:48,500 --> 00:00:50,689 And the thing about random is that it's so powerful, 14 00:00:50,700 --> 00:00:54,090 it has so many methods that comes with it. 15 00:00:54,680 --> 00:01:00,369 Take a look at the choice method. This will return a random element 16 00:01:00,700 --> 00:01:05,900 from the given sequence. And we're gonna make use of this particular method 17 00:01:06,129 --> 00:01:09,080 to generate a random letter. So 18 00:01:09,199 --> 00:01:10,900 check this out. OK. 19 00:01:11,290 --> 00:01:16,889 I'm gonna first of all create a variable called letters and then equals two 20 00:01:17,120 --> 00:01:18,379 and I'm gonna type in 21 00:01:18,849 --> 00:01:22,540 all the letters in here A to Z. OK. 22 00:01:22,879 --> 00:01:23,419 So 23 00:01:23,779 --> 00:01:30,949 we want our program to generate a random letter from this list. OK? 24 00:01:30,959 --> 00:01:31,989 From this sequence. 25 00:01:32,190 --> 00:01:32,739 So 26 00:01:32,980 --> 00:01:34,620 how are we gonna do this? Well, 27 00:01:34,940 --> 00:01:38,620 I am going to create a new variable called a random 28 00:01:39,430 --> 00:01:40,620 on the call letter. 29 00:01:40,949 --> 00:01:41,580 OK. 30 00:01:41,959 --> 00:01:45,540 And now in here, I am going to say random. 31 00:01:45,849 --> 00:01:47,199 Remember the sequence. 32 00:01:47,209 --> 00:01:51,540 First of all, we'll have to add the name of the module library. So it's random in here. 33 00:01:51,980 --> 00:01:53,389 And now the mode, 34 00:01:53,540 --> 00:01:56,650 the method which is choice is gonna be dot 35 00:01:56,919 --> 00:01:58,650 And now choice. 36 00:01:58,910 --> 00:02:00,339 And now in brackets 37 00:02:00,709 --> 00:02:01,900 letters, 38 00:02:03,239 --> 00:02:06,720 that is all I have to do. And now 39 00:02:07,099 --> 00:02:07,910 what do we do? 40 00:02:08,070 --> 00:02:09,339 We print out 41 00:02:10,639 --> 00:02:11,699 and I can say 42 00:02:12,550 --> 00:02:16,169 the random letter chosen 43 00:02:16,520 --> 00:02:17,580 is 44 00:02:17,750 --> 00:02:18,539 and then 45 00:02:18,660 --> 00:02:23,559 I can add my comma and then simply add random underscore letter. 46 00:02:24,559 --> 00:02:25,539 And there it is, 47 00:02:26,059 --> 00:02:28,720 that's all we have to do. So now if I run 48 00:02:29,000 --> 00:02:30,039 the program 49 00:02:30,240 --> 00:02:34,139 there it is, the random letter chosen is M OK. 50 00:02:34,509 --> 00:02:38,580 Let's try running the program again. Maybe we will choose a different letter. 51 00:02:38,589 --> 00:02:39,240 It should. 52 00:02:39,649 --> 00:02:41,580 And there you go. Now it's C 53 00:02:41,990 --> 00:02:43,369 again. Now it's a 54 00:02:43,809 --> 00:02:48,179 one more time. Now it is V you can see right now it actually works. 55 00:02:48,350 --> 00:02:50,039 So a quick recap. What did we do? 56 00:02:50,050 --> 00:02:54,669 First of all, we imported the standard module called random 57 00:02:54,869 --> 00:02:57,669 that has a list of different types of methods 58 00:02:57,860 --> 00:02:59,000 that will generate a 59 00:02:59,679 --> 00:03:00,619 random letter. 60 00:03:00,899 --> 00:03:03,750 So the first thing we did was that we created our letters 61 00:03:03,759 --> 00:03:07,470 variable that will hold all the letters from A to Z. 62 00:03:07,910 --> 00:03:10,820 And then we assigned another variable called random letter 63 00:03:11,059 --> 00:03:13,699 that will now hold the actual 64 00:03:14,270 --> 00:03:17,970 letter that will be generated, the actual random letter that was generated. 65 00:03:18,210 --> 00:03:20,059 And then we said random bin, 66 00:03:20,070 --> 00:03:24,309 the name of the module and then appended the method which is choice 67 00:03:24,470 --> 00:03:26,779 and then in brackets letters 68 00:03:26,960 --> 00:03:28,630 and now we simply printed out 69 00:03:28,740 --> 00:03:30,380 the random letter that was chosen 70 00:03:30,490 --> 00:03:32,220 in line four. 71 00:03:32,470 --> 00:03:35,889 So that's it. Thank you for watching the video. I will see you in the next class.