LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S \$294 IN SAVINGS). # Guided Project: mobile app last step

Screen Link: Learn data science with Python and R projects

My Code:

``````def probability_less_6(n_winning_numbers):
n_combinations_ticket = combinations(6, n_winning_numbers)
n_combinations_remaining = combinations(43, 6 - n_winning_numbers)
successful_outcomes = n_combinations_ticket * n_combinations_remaining

n_combinations_total = combinations(49,6)
probability = successful_outcomes / n_combinations_total

probability_percentage = probability * 100
combinations_simplified = round(n_combinations_total/successful_outcomes)
print('''Your chances of having {} winning numbers with this ticket are {:.6f}%.
In other words, you have a 1 in {:,} chances to win.'''.format(n_winning_numbers, probability_percentage, int(combinations_simplified)))

``````

n_combinations_remaining = combinations(43, 6 - n_winning_numbers)
why it needs to use 6 minus n_winning_numbers?

Here’s the guideline:

• First, calculate the number of successful outcomes given the value of the input. We already covered how to calculate this when the input is `5` — when the input is lower, we need to take the same approach (but be careful, the number of combinations will vary). If you get stuck, try to sneak a look at the solution notebook.
• Second, calculate the number of total possible outcomes.

Best,
Jessie

If `n_winning_numbers` is `2` that means you want to find the probability that the ticket has `2` winning numbers.

We calculate `n_combinations_ticket` knowing we have `2` winning numbers.

But, that means, there are still `4` numbers left that need to be selected for the ticket. That’s why we have `6 - n_winning_numbers` or `6 - 2 = 4`.