
Probability of Winning the Lottery
Using Python to determine your odds of success
21 July, 2022
9
9
0
Contributors
Have you ever thought about how different your life would be if you won the lottery? The Lottery seems like a quick get-rich plan that so many people dream about. According to ABC News, the Powerball reached a whopping $1.586 billion (Powerball) in 2016...
Obviously, to win the ultimate million or billion-dollar jackpot, you would have to defy the monumental odds. According to the review journal, the following events have a higher chance of happening than you winning the lottery.
•
Being Crushed by a Meteorite
•
Becoming the Next Warren Buffet
•
Death by Hot Tap Water
•
Being a U.S. President

Photo by Srikanta H. U on Unsplash
Let’s assume that our lottery is structured where each time six numbers are drawn from a pool of numbers ranging from 1–49. If you’re not familiar with how the lottery works, the customer who selects his/her six numbers must get it exactly the same as the winning numbers. If one number differs, they do not win the big jackpot.
To get started we will first need to create some functions.
Factorial Function:
Factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n: For example, The value of 0! is 1, according to the convention for an empty product.
Combination Function:
Combinations area selection of items from a collection, such that the order of selection does not matter. Here is a good read if you want to learn more.
Single Lottery Ticket Function:
Now let’s calculate the probability of winning with a single ticket purchased.
Some important thing to notice,
1. total_outcomes - uses the combination formula we made earlier, passing in the total amount of possible numbers 49 and the number of options 6.
2. successful_outcomes - there is only one winner, as mentioned earlier, so only one ticket wins.
There are precisely 13,983,816 chances to win (total_outcomes),
If we were to run this function on a sample of 6 numbers selected for a single ticket, we would get the following.
Output:
“You’re chances of winning are 0.0000000000005113857220%!”
“Choose to be optimistic, it feels better.”
– Dalai Lama
What happens if you buy multiple tickets? How much better will your odds be if you purchase tickets in bulk?

Image by Alejandro Garay from Pixabay
Multiple Lottery Ticket Function:
As you can see, I kept the main chunk of the code the same as the single_ticket function, but now I added code to simplify the combinations. I also added String Formatting at the end to help produce a more readable output.
Let’s test the code using a variety of ticket amounts and a for loop.
The output would look something like this.
As expected, we can see as the number of tickets purchased increases, the odds of winning increase. The last line shows we have a 100% chance of winning if we are buying 13,983,816 that’s because we calculated earlier that the total amount of possible outcomes is 13,983,816
Understanding the process and code structure to calculating lottery probability is a stepping stone to endless possibilities with diving deeper into the world of data science.
What are some other exciting ways to use probabilities?
“The consequences of an act affect the probability of its occurring again.”
- B. F. Skinner
python
data science