{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Write your solution in one or more cells after each problem.
Always show your work.
You can use Python library functions
or write your own functions and other support code."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Two tennis-playing friends, Deborah and Robert, keep track of who won their games based on the lengths of their pregame warm-up times:\n",
"
\n",
"\n",
"Warm-up time | \n",
"Deborah wins | \n",
"Robert wins | \n",
"Total | \n",
"
\n",
"\n",
"Short | 4 | 6 | 10 | \n",
"
\n",
"\n",
"Long | 16 | 24 | 40 | \n",
"
\n",
"\n",
"Total | 20 | 30 | 50 | \n",
"
\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# data analysis and wrangling\n",
"import pandas as pd\n",
"import numpy as np\n",
"import math\n",
"import statistics\n",
"from scipy.stats import binom"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
"\n",
"\n",
" | \n",
"Warm-up time | \n",
"Deborah wins | \n",
"Robert wins | \n",
"Total | \n",
"
\n",
"\n",
"\n",
"\n",
"0 | \n",
"Short | \n",
"4 | \n",
"6 | \n",
"10 | \n",
"
\n",
"\n",
"1 | \n",
"Long | \n",
"16 | \n",
"24 | \n",
"40 | \n",
"
\n",
"\n",
"2 | \n",
"Total | \n",
"20 | \n",
"30 | \n",
"50 | \n",
"
\n",
"\n",
"
\n",
"
"
],
"text/plain": [
" Warm-up time Deborah wins Robert wins Total\n",
"0 Short 4 6 10\n",
"1 Long 16 24 40\n",
"2 Total 20 30 50"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# initialise data of lists. \n",
"data = {'Warm-up time':['Short', 'Long', 'Total'], 'Deborah wins':[4, 16, 20],'Robert wins':[6, 24, 30],'Total':[10, 40, 50]} \n",
" \n",
"# Creates pandas DataFrame. \n",
"df = pd.DataFrame(data) \n",
" \n",
"# print the data \n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"####
PROBLEM 1.a. What is the probability that Deborah wins the next game if she had a short warm-up time?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that Deborah wins the next game if she had a short warm-up time is: 0.2\n"
]
}
],
"source": [
"# Define function \"probability\"\n",
"def pro(No_fav_cases,Total_No_Events):\n",
" return(round(No_fav_cases/Total_No_Events,2))\n",
"\n",
"\n",
"print(\"The probability that Deborah wins the next game if she had a short warm-up time is: \",pro(df.iloc[0,1],df.iloc[2,1]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"####
PROBLEM 1.b. Deborah won the last game! What is the probability that she had a short warm-up time before the game?"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The probability that Deborah had a short warm-up time before the game is: 0.33\n"
]
}
],
"source": [
"# Define function \"before probability\"\n",
"def...