Hello and welcome to this video.
I'll be showing you how to create a very simple program in Python that you can use to assimilate the
generation of lottery numbers or Just Six Numbers the concepts we can to use in this program include
importing a module so going to import the random module that contains functions that all let us generate
random numbers.
Also going to create a list we're going to be using loop.
So be using the for loop and also a while loop.
We're also going to use a function from the random module called round it that is used to generate random
integers an integer is basically a whole number.
Also going to be using some functions from the list.
So going to be using the append and the sort function from a list we will also be using the print function
to print out the random numbers that have been generated.
We are going to also use a range function a ranked function is basically used to return a sequence of
numbers.
I'm going to be using pi charm which is a python editable or IDB.
So this is my PI Tom idc.
I've already got a directory where I have some Python files I have been using.
So I'm going to create a new file inside this directory.
So I'm going to right click and go new and typing python file.
I'm just going to call this lottery and it will append it with a dot P Y extension.
So this is it here just created the first 10 I want to do is import the module called random which contains
functions that I would use to generate a random number.
So you type in import space and the word random and that imports the module called Random.
Next thing I want to do is initialize an empty list that will store the six numbers that will be generated.
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
to course to an empty list because there's nothing else in the list at the moment I just want to initialize
the list.
The next thing I want to do is add a for loop and specify a range.
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.
So what that means it will generate six numbers from a list that the front end function will pull from.
So that is the for loop and inside that for loop I'm going to create a variable called number and I'm
going to set that variable to equals to random.
So I'm referencing the module called random and from that module core random I'm going to use a function
called Rand int that's the function that we generate then random numbers.
And inside that Rand int function and we need to give it a range of numbers to generate from.
So I'll give it one to 50.
So what that means it will pick out six numbers from one to 50 because inside this range are specified
0 2 6 so it will from this block from 1 to 50 to generate any random 6 numbers.
And I want to add a while loop while loop basically will execute a set of statements as long as a condition
is true while the for loop is used for iterating over a sequence so the for loop will be used to looping
through the sequence and then print out any six numbers that was generated.
So I'll say while the variable called number in the verbal code lottery on the score number which is
the list.
And now add the call on here.
So this is.
And then the code.
I'm going to write.
Just notice the indentation.
So any code on the here will be the code for the while loop to execute.
So.
So while the number is equal to random dot round INT and then again that run date is 50.
So as long as it keeps generating six numbers from this block anything from one to 50.
So those are the condition.
All right.
And then need to invent indentation is very important so that your code will execute correctly.
So notice my indentation here this one is on the same level as the while loop.
So now after the while loop I want to be able to any number that is being generated.
I want to use a list method called append to drop that number into this empty list I created on line
number three.
So what I'll do.
Lottery on the score.
Numbers dot append.
Okay.
So this will append any number that is being generated an hour pass in the variable code number which
is is variable here.
All right.
So this append drops any number that is randomly generated in to the list and then I'm going to indent
on another level.
So notice as this here or here this lottery here whatever number gets appended here is for this for
loop so all of this code here under the for loop.
So now you can see of indented.
So this indentation is on the same level of the for loop.
So while I'm going to do now is now at this stage all the numbers have been generated.
The six numbers and there would have been appended to the list.
So what I need to do now I want to sort it so that the numbers are sorted inside the list.
So to do that I'll do lottery on the score numbers dot sort.
So this sort method will sort the items in the list.
And the final thing to do here is just to print out the outcome on the screen.
So we do lottery on the score numbers and that we just print out whatever number was generated and placed
in the list.
OK.
Let's run the code and see if it works.
So when each time you create a new python file inside the PI charm you have to right click and run the
file before it shows up there.
All right.
So click on the play button or you can right click and click Run whatever you've called your file somewhere
click on this play and you can see here is generated six numbers and you can see sorted them in that
order to 17 and so on.
So let's generate another one.
Click on play again.
You can see it's generated different set of numbers.
I'll do one more play and you can see.
All right.
So this concludes the little program that will generate random six numbers which can be used to simulate
lottery numbers or other type of numbers that you're trying to generate.
So that's it.
I hope the video has been useful.
Thank you for watching.
Bye for now.