Queer European MD passionate about IT
Ver Fonte

Merge pull request #91 from dataquestio/fix/alex/bug_gp_proba

Fix bug in M382
Alex há 5 anos atrás
pai
commit
7c397eabb0
1 ficheiros alterados com 23 adições e 19 exclusões
  1. 23 19
      Mission382Solutions.ipynb

+ 23 - 19
Mission382Solutions.ipynb

@@ -605,7 +605,9 @@
     "    - 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 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."
+    "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.\n",
+    "\n",
+    "The function below calculates the probability that a player's ticket matches exactly the given number of winning numbers. If the player wants to find out the probability of having five winning numbers, the function will return the probability of having five winning numbers exactly (no more and no less). The function will not return the probability of having _at least_ five winning numbers."
    ]
   },
   {
@@ -617,16 +619,14 @@
     "def probability_less_6(n_winning_numbers):\n",
     "    \n",
     "    n_combinations_ticket = combinations(6, n_winning_numbers)\n",
-    "    n_combinations_remaining = combinations(49 - n_winning_numbers,\n",
-    "                                           6 - n_winning_numbers)\n",
+    "    n_combinations_remaining = combinations(43, 6 - n_winning_numbers)\n",
     "    successful_outcomes = n_combinations_ticket * n_combinations_remaining\n",
-    "    n_combinations_total = combinations(49, 6)\n",
     "    \n",
+    "    n_combinations_total = combinations(49, 6)    \n",
     "    probability = successful_outcomes / n_combinations_total\n",
-    "    probability_percentage = probability * 100\n",
-    "    \n",
-    "    combinations_simplified = round(n_combinations_total/successful_outcomes)\n",
     "    \n",
+    "    probability_percentage = probability * 100    \n",
+    "    combinations_simplified = round(n_combinations_total/successful_outcomes)    \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",
     "                                                               int(combinations_simplified)))"
@@ -648,17 +648,17 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "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",
+      "Your chances of having 2 winning numbers with this ticket are 13.237803%.\n",
+      "In other words, you have a 1 in 8 chances to win.\n",
       "--------------------------\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",
+      "Your chances of having 3 winning numbers with this ticket are 1.765040%.\n",
+      "In other words, you have a 1 in 57 chances to win.\n",
       "--------------------------\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",
+      "Your chances of having 4 winning numbers with this ticket are 0.096862%.\n",
+      "In other words, you have a 1 in 1,032 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",
+      "Your chances of having 5 winning numbers with this ticket are 0.001845%.\n",
+      "In other words, you have a 1 in 54,201 chances to win.\n",
       "--------------------------\n"
      ]
     }
@@ -680,12 +680,16 @@
     "- `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 two, three, four or five winning numbers\n",
+    "- `probability_less_6()` — calculates the probability of having two, three, four or five winning numbers exactly\n",
     "\n",
     "Possible features for a second version of the app include:\n",
     "\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",
-    "- Combining 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\n",
+    "- Create a function similar to `probability_less_6()` which calculates the probability of having _at least_ two, three, four or five winning numbers. Hint: the number of successful outcomes for having at least four winning numbers is the sum of these three numbers:\n",
+    "    - The number of successful outcomes for having four winning numbers exactly\n",
+    "    - The number of successful outcomes for having five winning numbers exactly\n",
+    "    - The number of successful outcomes for having six winning numbers exactly"
    ]
   }
  ],
@@ -705,9 +709,9 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.6.8"
+   "version": "3.7.3"
   }
  },
  "nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
 }