How To Win The Powerball With This Simple Python Script

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up everyone my name is Cody Engel I am a software engineer and I'm finally ready to put my software engineering skills to good use and win the Powerball by writing a python script so as I say time is money so let's just get into it and I'll walk you through what I'm going to do so the first thing I want to do is look up the Powerball winning lottery number history I want to be a Json file because I want to read that file looks like this one might have that information for us there's a Json file can I open it yes so I can open it and it looks like the file has a ton of information for us looks like it has some winning lottery numbers so we're in business the next step is to figure out how to do python because I've never done that before I think vs code is what a lot of people use so we'll go ahead and try that out the next thing for me to do is to create a file and we will just call this Powerball dot Pi because I believe dot Pi is what python files end with and the first thing I want to do is just make sure that I have python set up correctly and know that I can run it so I'm just going to do print hello world we will go ahead and run it from their terminal if I can find their terminal you can tell I don't really actually use vs code that often all right so now that I finally found the terminal let's type in python3 and then powerball.pi and nothing right oh I didn't save the file let's try that again cool so remembering inside of the file it now works so the next thing to do is to actually figure out how do I download this Json file because that's really the first step is getting that Json file onto my machine so that I can start reading all the numbers and figuring out which ones are most likely to win so this lets me know how to download something over HTTP this looks like I can probably copy and paste it over here we will do that so there's our request this I think will save it as the file name so actually instead of that I think what I would pry on is this to be called powerball.json and then instead of this being an MP3 file I actually want that to be the Json file that we found at the beginning of this video so we'll paste that in save the file and then we will go ahead and rerun it and we'll see if it downloads the file which over here on the this side looks like it did download it so the next thing I'm going to do is I'm going to comment out this because I actually don't need to keep downloading the file over and over again while I'm working on this I don't know if they have any rate limiting in place but it doesn't really make sense for me to constantly download this every time I'm re-running the script the next thing that I really want to do is be able to read the Json file and this article from Geeks for geeks looks like it will probably do the tricks so let's go ahead and get that into the app now first up I just want to do file and then equals open this will open up our file and our file is called powerball.json then I want to load all of the Powerball records from the Json file into just a variable so we can make use of it then because I'm a good person I'm going to close the file essentially just we don't need the file open anymore it's already in memory and then probably the last thing I want to do is actually import Json because we need to use Json to load Json with that in place I can't really test it out quite yet so we're just going to do another print to make sure that it's loading the Json file correctly and we will go ahead and rerun it by doing our Python 3 powerball.pi or just pressing up on the keyboard to rerun the last command that looks like the Json file alright so we're one step closer to winning millions of dollars for doing pretty much nothing so the next thing that we want to do now that we know that we can actually load the Json file and view everything is we want to extract the winning lottery numbers from the file and then we can start doing some python magic with it first thing that we want to do is actually figure out what the numbers are and so from looking at the file it looks like there is this data key and then from there it looks like we have the Powerball numbers along with a like multiplier we don't need to worry about the multiplier really just need to worry about the numbers themselves so this is one two three four five six numbers from looking at the Powerball lottery website looks like one two three four five and then the sixth number is the Powerball the next thing we want to do is actually go through and like I said categorize numbers so Powerball number occurrence is what we could use and this is just going to be stored in a map I think that's how you do a map in Python and then regular number occurrence will be in its own map as well so this way we will kind of break things up into regular numbers and then Powerball numbers and essentially what we're going to do is count up how many times those individual numbers occur and then at the very end we'll figure out which ones occur the most often and then that will give us the best odds of winning the lottery in order to kind of categorize all of these we'll have a Powerball record in Powerball records um coming from the data key and the next thing is to get the Powerball numbers which will be a Powerball record and it needs to come from the occurrence in this array of objects so we have one two three four five six seven eight nine ten but because arrays are zero indexed this will be at index number nine back over here we will do nine and then just make sure that works we will print out the Powerball numbers and this will let us know are we on the right path so running this again yes it looks like we are printing out just the Powerball numbers we're only getting those that is what we wanted so the next step is really figuring out how many times those individual numbers are occurring absent the Powerball because that's treated as a separate number but the other numbers they can only occur once so that's kind of why we're grouping those together so let's go ahead and get that done now similar last time we'll comment out the print because we don't need that anymore and what we want to do is basically have this regular numbers array that's going to be our Powerball numbers we will split on the space character so this will create an array for US based on this string of numbers but it'll have all the numbers in them we don't want all the numbers we only want the first five so it's pretty simple for us to do essentially just regular numbers array dot pop that will remove the last number from the array and then similar and we're just going to print out the regular numbers array make sure that it only contains five numbers basically at this point in time we rerun it we have one two three four five that's what we want and we will also notice that it's an array which is what we want as well then we will start tracking those numbers and the way that we want to do that is by doing four regular number in our regular number occurrence and then if regular number in regular number occurrence essentially saying if this number already exists then we will grab the current occurrences from it because that's what we're doing we're tracking the occurrences and then since we have the occurrences now we can do occurrences plus equals one so increase it and then we will just do regular number occurrences for that regular number and we will set it equal to the occurrences that's now updated by one if it's the first time that we're seeing it then we need to have a case where we're just adding it to the map so we'll just do regular number of currents and again regular number and we'll set it equal to one we can now print out our regular number of currents see how that's working for us and it's not and the reason why it's not working is because this actually needs to be regular number array So reading from our array and putting them into our currents rerunning the script now with it working we can see all right so 11's occurred 117 times 21 118 times and so on so on looks like it's counting up the numbers like you would want to so the next thing we want to do is we want to sort those regular numbers based on their occurrences because we basically just want the ones that occur most often to figure out which ones are most likely to be picked so we will have a regular number occurrence sorted and it'll be equal to this sorted function that python has built in we'll take our number occurrence grab the items so the actual like how many times it occurred we set this key to be equal to this Lambda that I found on stack Overflow not 100 sure how it's working I'm thinking it's just sorting it basically by the second value I think and then because I want these to be sorted from most occurrences to least occurrences we want it to be in reverse order because by default it will sort it basically by lowest to greatest so we say reverse equals true and then print by our sorted and then we will go ahead and run this to see if it works and open it up we can see this 32 132 132 36 131 so yes it does in fact look like it is sorting it the way that we want it to now what I want to do is basically the exact same thing except for the Powerball numbers so this is going to be pretty fun it's just a bunch of copy and paste so the first thing I'm going to do is come back up here and I'm going to set this value to be Powerball number so the way that the pop function works so not only does it remove the last item but it returns that last item too so we can remove it then we can store it into this Powerball variable and then essentially we're just going to do this exact same thing except instead of for regular number it's going to be for the Powerball number and so you can see here we're checking if the Powerball number already exists in the occurrence and chronic by one if it doesn't then we just create a new value so the exact same thing like I said that we've been doing copy and pasting is always fun and then our sorting can also be done with the magic of copy and paste and then we just go ahead and print our Powerball number current sorted and you can see it does in fact look like the Powerball numbers are sorted from greatest to least now at this point we're pretty much done just have a couple more more finishing touches so if you've been enjoying this video up until this point in time please go ahead and smash like button be sure to subscribe if you like the style of context there will be more of this in the future and let's actually finish this up and and go win the lottery so what I want to do is basically write these into their own list because at this point in time we can't really do a ton with this we know that 24 and 65 like that's the number and then the occurrence but I really only care about the number I've already sorted it into that correct order and so essentially I just want to transform this sorted map into a list that only contains the lottery numbers the next thing that I want to do is create a new variable called winning ticket because this is going to be our winning ticket number and I want this to be created as a string where each number is separated by a space and to do that we basically have this space and then dot join so we're going to be joining some numbers together and the first set are going to be our number occurrence sorted by occurrence that's a mouthful that's what she said that's what that's what she said um and we're going to take the first five of those numbers and then we're going to add that with our Powerball number the current sorted by occurrence and we only want the first one of those and the last thing we want to do is just do print and winning ticket and then this is like a weird string formatting way with python but it's basically on a lot of inject the winning ticket number that we have and drumroll please and it didn't work and the reason why it didn't work is because I used the wrong value for Powerball number so you know measure once cut twice whatever basically what I'm doing I guess so Our Winning Powerball or Our Winning Ticket is 32 39 36 23 59 24. and let's go ahead and see how often that one has occurred for us at least just for like the first five because it's probably occurred a couple of times it's the most popular number so we go back over to our Powerball Json we do command F and then search and um no no results I guess they usually do give the results sorted by number so maybe like 23 and we'll get rid of that 39 no okay maybe maybe no no we're just going down the list okay so we had 39 so 23 30 32 39 that one has occurred has 36 occur no no so this is a little embarrassing but let's let's actually hold on let me look at some numbers real quick I I really can't believe I didn't do this before but let's do odds of winning power Powerball hey look at that one in 292 million 201 338 so it's it's pretty fair to say I'm probably not going to win the the Powerball hopefully my employer still wants me to work with them um but the really great thing if you made it all the way to this part of the video is even though you're probably not going to be able to win the Powerball using this python script you do have some exposure to writing a python script now and if we just look at salary.com python is paying about ninety seven thousand dollars on average but I mean I know just from working in the industry you can make a lot more than that and you can still be writing python making a lot more than that so even though you didn't win the lottery you could have exposure to programming and if this was something that sounded fun and enjoyable well maybe just keep at it and within no time you'll be able to get a software engineering job and if you want to learn about the different companies that you can work for as a software engineer check out this playlist next it will talk about some really good companies to work for the different salaries that you can expect different benefits all of that good stuff and until next time it's been great and if you do win the lottery uh just just remember who who gave you the python script um maybe maybe send me like five bucks but
Info
Channel: Cody Engel
Views: 25,006
Rating: undefined out of 5
Keywords: cody engel, python, lottery, lotto, powerball, mega millions, win the lottery, how to win the lottery, win the lottery with python, python lottery, how to win the powerball, how to win the mega millions
Id: hPucbi0H1EI
Channel Id: undefined
Length: 13min 36sec (816 seconds)
Published: Sun Mar 12 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.