Queer European MD passionate about IT
Эх сурвалжийг харах

Merge branch 'master' of github.com:dataquestio/solutions

Christian Pascual 5 жил өмнө
parent
commit
6147e60a73
1 өөрчлөгдсөн 21 нэмэгдсэн , 16 устгасан
  1. 21 16
      Mission382Solutions.ipynb

+ 21 - 16
Mission382Solutions.ipynb

@@ -596,16 +596,16 @@
    "source": [
     "## Less Winning Numbers — Function\n",
     "\n",
-    "In most 6/49 lotteries, there are smaller prizes if a player's ticket match three, four, or five of the six numbers drawn. This means that players might be interested in finding out the probability of having three, four, or five winning numbers — for the first version of the app, users should be able to find those probabilities.\n",
+    "In most 6/49 lotteries, there are smaller prizes if a player's ticket match two, three, four, or five of the six numbers drawn. This means that players might be interested in finding out the probability of having two, three, four, or five winning numbers — for the first version of the app, users should be able to find those probabilities.\n",
     "\n",
     "These are the details we need to be aware of when we write a function to make the calculations of those probabilities possible:\n",
     "\n",
     "- Inside the app, the user inputs:\n",
     "    - six different numbers from 1 to 49; and\n",
-    "    - an integer between 3 and 5 that represents the number of winning numbers expected\n",
+    "    - an integer between 2 and 5 that represents the number of winning numbers expected\n",
     "- Our function prints information about the probability of having a certain number of winning numbers\n",
     "\n",
-    "To calculate the probabilities, we tell the engineering team that the specific combination on the ticket is irrelevant and we only need the integer between 3 and 5 representing the number of winning numbers expected. Consequently, we will write a function named `probability_less_6()` which takes in an integer and prints information about the chances of winning depending on the value of that integer."
+    "To calculate the probabilities, we tell the engineering team that the specific combination on the ticket is irrelevant and we only need the integer between 2 and 5 representing the number of winning numbers expected. Consequently, we will write a function named `probability_less_6()` which takes in an integer and prints information about the chances of winning depending on the value of that integer."
    ]
   },
   {
@@ -617,12 +617,15 @@
     "def probability_less_6(n_winning_numbers):\n",
     "    \n",
     "    n_combinations_ticket = combinations(6, n_winning_numbers)\n",
-    "    n_combinations_total = combinations(49, n_winning_numbers)\n",
+    "    n_combinations_remaining = combinations(49 - n_winning_numbers,\n",
+    "                                           6 - n_winning_numbers)\n",
+    "    successful_outcomes = n_combinations_ticket * n_combinations_remaining\n",
+    "    n_combinations_total = combinations(49, 6)\n",
     "    \n",
-    "    probability = n_combinations_ticket / n_combinations_total\n",
+    "    probability = successful_outcomes / n_combinations_total\n",
     "    probability_percentage = probability * 100\n",
     "    \n",
-    "    combinations_simplified = n_combinations_total\n",
+    "    combinations_simplified = round(n_combinations_total/successful_outcomes)\n",
     "    \n",
     "    print('''Your chances of having {} winning numbers with this ticket are {:.6f}%.\n",
     "In other words, you have a 1 in {:,} chances to win.'''.format(n_winning_numbers, probability_percentage,\n",
@@ -645,20 +648,23 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Your chances of having 3 winning numbers with this ticket are 0.108554%.\n",
-      "In other words, you have a 1 in 18,424 chances to win.\n",
+      "Your chances of having 2 winning numbers with this ticket are 19.132653%.\n",
+      "In other words, you have a 1 in 5 chances to win.\n",
       "--------------------------\n",
-      "Your chances of having 4 winning numbers with this ticket are 0.007080%.\n",
-      "In other words, you have a 1 in 211,876 chances to win.\n",
+      "Your chances of having 3 winning numbers with this ticket are 2.171081%.\n",
+      "In other words, you have a 1 in 46 chances to win.\n",
       "--------------------------\n",
-      "Your chances of having 5 winning numbers with this ticket are 0.000315%.\n",
-      "In other words, you have a 1 in 1,906,884 chances to win.\n",
+      "Your chances of having 4 winning numbers with this ticket are 0.106194%.\n",
+      "In other words, you have a 1 in 942 chances to win.\n",
+      "--------------------------\n",
+      "Your chances of having 5 winning numbers with this ticket are 0.001888%.\n",
+      "In other words, you have a 1 in 52,969 chances to win.\n",
       "--------------------------\n"
      ]
     }
    ],
    "source": [
-    "for test_input in [3, 4, 5]:\n",
+    "for test_input in [2, 3, 4, 5]:\n",
     "    probability_less_6(test_input)\n",
     "    print('--------------------------') # output delimiter"
    ]
@@ -674,13 +680,12 @@
     "- `one_ticket_probability()` — calculates the probability of winning the big prize with a single ticket\n",
     "- `check_historical_occurrence()` — checks whether a certain combination has occurred in the Canada lottery data set\n",
     "- `multi_ticket_probability()` — calculates the probability for any number of of tickets between 1 and 13,983,816\n",
-    "- `probability_less_6()` — calculates the probability of having three, four or five winning numbers\n",
+    "- `probability_less_6()` — calculates the probability of having two, three, four or five winning numbers\n",
     "\n",
     "Possible features for a second version of the app include:\n",
     "\n",
-    "- Improve the `probability_less_6()` function to show the probabilities for having two numbers as well.\n",
     "- Making the outputs even easier to understand by adding fun analogies (for example, we can find probabilities for strange events and compare with the chances of winning in lottery; for instance, we can output something along the lines \"You are 100 times more likely to be the victim of a shark attack than winning the lottery\")\n",
-    "- Combine the `one_ticket_probability()`  and `check_historical_occurrence()` to output information on probability and historical occurrence at the same time"
+    "- Combining the `one_ticket_probability()`  and `check_historical_occurrence()` to output information on probability and historical occurrence at the same time"
    ]
   }
  ],