1 00:00:00,450 --> 00:00:02,770 Hello and welcome to this video. 2 00:00:02,860 --> 00:00:13,080 I'll be showing you how to create a very simple program in Python that you can use to assimilate the 3 00:00:13,290 --> 00:00:25,190 generation of lottery numbers or Just Six Numbers the concepts we can to use in this program include 4 00:00:25,310 --> 00:00:34,010 importing a module so going to import the random module that contains functions that all let us generate 5 00:00:34,100 --> 00:00:35,850 random numbers. 6 00:00:35,930 --> 00:00:40,610 Also going to create a list we're going to be using loop. 7 00:00:40,620 --> 00:00:45,340 So be using the for loop and also a while loop. 8 00:00:45,350 --> 00:00:53,750 We're also going to use a function from the random module called round it that is used to generate random 9 00:00:53,900 --> 00:00:58,440 integers an integer is basically a whole number. 10 00:00:58,580 --> 00:01:02,980 Also going to be using some functions from the list. 11 00:01:03,200 --> 00:01:13,310 So going to be using the append and the sort function from a list we will also be using the print function 12 00:01:13,820 --> 00:01:18,650 to print out the random numbers that have been generated. 13 00:01:18,650 --> 00:01:28,250 We are going to also use a range function a ranked function is basically used to return a sequence of 14 00:01:28,430 --> 00:01:29,690 numbers. 15 00:01:29,690 --> 00:01:37,050 I'm going to be using pi charm which is a python editable or IDB. 16 00:01:37,130 --> 00:01:40,550 So this is my PI Tom idc. 17 00:01:40,610 --> 00:01:46,930 I've already got a directory where I have some Python files I have been using. 18 00:01:47,090 --> 00:01:50,430 So I'm going to create a new file inside this directory. 19 00:01:50,570 --> 00:01:56,050 So I'm going to right click and go new and typing python file. 20 00:01:56,270 --> 00:02:04,990 I'm just going to call this lottery and it will append it with a dot P Y extension. 21 00:02:05,030 --> 00:02:13,370 So this is it here just created the first 10 I want to do is import the module called random which contains 22 00:02:13,550 --> 00:02:16,600 functions that I would use to generate a random number. 23 00:02:16,640 --> 00:02:26,090 So you type in import space and the word random and that imports the module called Random. 24 00:02:26,130 --> 00:02:34,130 Next thing I want to do is initialize an empty list that will store the six numbers that will be generated. 25 00:02:34,130 --> 00:02:44,940 So I'm gonna give the list a name so I'm gonna call it lottery on the score numbers and I'll set that 26 00:02:44,940 --> 00:02:53,400 to course to an empty list because there's nothing else in the list at the moment I just want to initialize 27 00:02:53,610 --> 00:02:54,490 the list. 28 00:02:54,780 --> 00:03:00,710 The next thing I want to do is add a for loop and specify a range. 29 00:03:00,720 --> 00:03:17,430 So I do for I n range and for that ring function I'm going to pass in two parameters we go 0 and 6. 30 00:03:17,450 --> 00:03:28,820 So what that means it will generate six numbers from a list that the front end function will pull from. 31 00:03:28,820 --> 00:03:37,520 So that is the for loop and inside that for loop I'm going to create a variable called number and I'm 32 00:03:37,520 --> 00:03:42,870 going to set that variable to equals to random. 33 00:03:43,010 --> 00:03:50,420 So I'm referencing the module called random and from that module core random I'm going to use a function 34 00:03:50,420 --> 00:03:55,940 called Rand int that's the function that we generate then random numbers. 35 00:03:55,940 --> 00:04:02,390 And inside that Rand int function and we need to give it a range of numbers to generate from. 36 00:04:02,960 --> 00:04:05,530 So I'll give it one to 50. 37 00:04:05,570 --> 00:04:12,800 So what that means it will pick out six numbers from one to 50 because inside this range are specified 38 00:04:12,890 --> 00:04:20,990 0 2 6 so it will from this block from 1 to 50 to generate any random 6 numbers. 39 00:04:20,990 --> 00:04:31,370 And I want to add a while loop while loop basically will execute a set of statements as long as a condition 40 00:04:31,460 --> 00:04:40,130 is true while the for loop is used for iterating over a sequence so the for loop will be used to looping 41 00:04:40,130 --> 00:04:45,980 through the sequence and then print out any six numbers that was generated. 42 00:04:45,980 --> 00:04:58,870 So I'll say while the variable called number in the verbal code lottery on the score number which is 43 00:04:58,870 --> 00:04:59,830 the list. 44 00:04:59,870 --> 00:05:02,770 And now add the call on here. 45 00:05:02,800 --> 00:05:04,210 So this is. 46 00:05:04,210 --> 00:05:05,280 And then the code. 47 00:05:05,320 --> 00:05:06,520 I'm going to write. 48 00:05:06,730 --> 00:05:08,350 Just notice the indentation. 49 00:05:08,680 --> 00:05:13,080 So any code on the here will be the code for the while loop to execute. 50 00:05:13,110 --> 00:05:13,280 So. 51 00:05:13,330 --> 00:05:28,570 So while the number is equal to random dot round INT and then again that run date is 50. 52 00:05:28,580 --> 00:05:35,440 So as long as it keeps generating six numbers from this block anything from one to 50. 53 00:05:35,510 --> 00:05:37,790 So those are the condition. 54 00:05:37,820 --> 00:05:38,480 All right. 55 00:05:38,480 --> 00:05:49,170 And then need to invent indentation is very important so that your code will execute correctly. 56 00:05:49,170 --> 00:05:55,080 So notice my indentation here this one is on the same level as the while loop. 57 00:05:55,080 --> 00:06:02,640 So now after the while loop I want to be able to any number that is being generated. 58 00:06:02,640 --> 00:06:10,650 I want to use a list method called append to drop that number into this empty list I created on line 59 00:06:10,650 --> 00:06:11,810 number three. 60 00:06:11,820 --> 00:06:13,940 So what I'll do. 61 00:06:14,880 --> 00:06:18,800 Lottery on the score. 62 00:06:19,040 --> 00:06:21,110 Numbers dot append. 63 00:06:21,960 --> 00:06:22,440 Okay. 64 00:06:22,860 --> 00:06:30,540 So this will append any number that is being generated an hour pass in the variable code number which 65 00:06:30,540 --> 00:06:32,060 is is variable here. 66 00:06:32,100 --> 00:06:32,460 All right. 67 00:06:32,460 --> 00:06:41,310 So this append drops any number that is randomly generated in to the list and then I'm going to indent 68 00:06:41,460 --> 00:06:43,170 on another level. 69 00:06:43,170 --> 00:06:52,880 So notice as this here or here this lottery here whatever number gets appended here is for this for 70 00:06:52,890 --> 00:06:55,860 loop so all of this code here under the for loop. 71 00:06:56,340 --> 00:06:58,540 So now you can see of indented. 72 00:06:58,540 --> 00:07:02,760 So this indentation is on the same level of the for loop. 73 00:07:02,760 --> 00:07:09,450 So while I'm going to do now is now at this stage all the numbers have been generated. 74 00:07:09,450 --> 00:07:12,940 The six numbers and there would have been appended to the list. 75 00:07:12,960 --> 00:07:19,080 So what I need to do now I want to sort it so that the numbers are sorted inside the list. 76 00:07:19,110 --> 00:07:27,530 So to do that I'll do lottery on the score numbers dot sort. 77 00:07:27,740 --> 00:07:32,770 So this sort method will sort the items in the list. 78 00:07:33,020 --> 00:07:40,580 And the final thing to do here is just to print out the outcome on the screen. 79 00:07:40,580 --> 00:07:52,220 So we do lottery on the score numbers and that we just print out whatever number was generated and placed 80 00:07:52,430 --> 00:07:54,040 in the list. 81 00:07:54,350 --> 00:07:54,880 OK. 82 00:07:54,980 --> 00:07:58,260 Let's run the code and see if it works. 83 00:07:58,280 --> 00:08:08,630 So when each time you create a new python file inside the PI charm you have to right click and run the 84 00:08:08,630 --> 00:08:10,880 file before it shows up there. 85 00:08:11,420 --> 00:08:12,310 All right. 86 00:08:12,350 --> 00:08:20,770 So click on the play button or you can right click and click Run whatever you've called your file somewhere 87 00:08:20,810 --> 00:08:28,760 click on this play and you can see here is generated six numbers and you can see sorted them in that 88 00:08:28,790 --> 00:08:31,910 order to 17 and so on. 89 00:08:31,910 --> 00:08:33,830 So let's generate another one. 90 00:08:33,980 --> 00:08:35,880 Click on play again. 91 00:08:35,900 --> 00:08:38,900 You can see it's generated different set of numbers. 92 00:08:38,910 --> 00:08:43,180 I'll do one more play and you can see. 93 00:08:43,280 --> 00:08:44,210 All right. 94 00:08:44,210 --> 00:08:52,970 So this concludes the little program that will generate random six numbers which can be used to simulate 95 00:08:53,090 --> 00:08:59,010 lottery numbers or other type of numbers that you're trying to generate. 96 00:08:59,030 --> 00:08:59,690 So that's it. 97 00:08:59,690 --> 00:09:01,490 I hope the video has been useful. 98 00:09:01,490 --> 00:09:02,660 Thank you for watching. 99 00:09:02,660 --> 00:09:03,350 Bye for now.