# Seven Detailed Examples Using The Addition Rule

Recall that the addition rule is used to calculate the probability that one event or another event (or both) occur.

Here is the formula:

### P(A or B) = P(A) + P(B) - P(A and B)

A detailed explanation of the addition rule is part of the DISCOVERY course content:

Before we begin, let's import our pandas library:

Now we're ready to dive into some examples! All of the examples on this page include a solution with manual calculations. The latter half of the examples also include a possible Python solution.

# Example 1: Milk Tea (Simple)

Kevin went to get milk tea at his go-to spot, TPumps. His drink toppings consists of 50% honey boba, 10% popping boba, and 40% lychee jelly. There's a 12.5% chance that Kevin gets both popping boba and lychee jelly in one sip of his milk tea. What is the probability that when Kevin takes his first sip of his milk tea, he gets either popping boba or lychee jelly?

#### Example 1 Solution:

###### Hand Calculations:

P(popping boba) = 0.1

P(lychee jelly) = 0.4

P(popping boba and lychee jelly) = 0.125.

We can then calculate:`P(popping boba or lychee jelly) = 0.1 + 0.4 - 0.125= 0.375`

# Example 2: A Lottery (Simple)

As recognition for completing a complex coding project, Emily and Dhiraj are entered into a lottery of 100 people for a gift card worth $1,000. The winner's name is randomly selected from a hat. What is the probability that Dhiraj or Emily's name is drawn as the winner of the gift card?

#### Example 2 Solution:

###### Hand Calculations:

P(Dhiraj) = 1⁄100 = 0.01

P(Emily) = 1⁄100 = 0.01

Dhiraj and Emily's names can't be drawn at the same time, meaning the two events are mutually exclusive! So P(Dhiraj and Emily) = 0

We can them calculate:`P(Emily or Dhiraj) = 0.01 + 0.01 = 0.02`

# Example 3: Newspaper Articles

Prompt: A newspaper corporation asked Talia to review the quality of their work by randomly selecting one of their articles from the past month to read. In the past month:

- 53 articles were written
- 21 of the articles focused on 'politics', 16 of the articles focused on 'food', and 16 focused on 'climate change'.
- 40 of the articles contained more than 1,000 words, and the rest contained less than 1,000 words.
- Of the articles containing more than 1,000 words, 18 focused on 'politics', 8 focused on 'food', and 14 focused on 'climate change'.

What is the probability that the article Talia randomly selects to read contains less than 1,000 words or focuses on the subject of food?

#### Example 3 Solution:

###### Hand Calculations:

P(less than 1,000 words) = ^{(53 - 40)}⁄_{53} = 13⁄53 = 0.2453

P(food) = 16⁄53 = 0.3019

P(food and less than 1,000 words) = P(food) * P(less than 1,000 words | food) = 0.3019 * 8⁄16 = 0.1509

We can then calculate:`P(food or less than 1,000 words) = 0.2453 + 0.3019 - 0.1509 = 0.3963`

A detailed explanation of the multiplication rule is part of the DISCOVERY course content:

# Example 4: Seats In a Stadium

In a stadium of 15,000 seats, 6,150 seats are located on the bottom level, 8,000 seats are located on the top level, and 850 seats are located on the balcony. For the upcoming football game, the ticket masters decide that 1,000 seats on the bottom level, 100 seats on the balcony level, and 6,000 seats on the top level will be sold for a ticket price less than $200.

What is the probability you can buy a seat that is either on the bottom level or for a ticket price less than $200?

#### Example 4 Solution:

###### Hand Calculations:

P(bottom level) = 6150⁄15000 = 0.41

P(price below $200) = ^{(1000 + 100 + 6000)}⁄_{15000} = 0.4733

P(bottom level and price below $200) = P(price below $200 | bottom level) * P(bottom level)

= (1000⁄6150) * 0.41 = 0.0667

We can then calculate:`P(bottom level or price below $200) = 0.41 + 0.4733 - 0.0667= 0.8166`

A detailed explanation of the multiplication rule is part of the DISCOVERY course content:

# Example 5: Jellyfish (with Python)

Karen went hiking up a mountain and stumbled upon a pond of jellyfish. Next to the pond stood a sign detailing the jellyfish in the pond: 5 Fried Egg Jellyfish, 3 Upside-Down Jellyfish, 6 Cannonball Jellyfish, and 3 Helmet Jellyfish as well as a warning not to swim in the pond.

Below is a DataFrame representing all the jellyfish living in the pond:

```
# Creating a DataFrame named 'pond' with 'type', 'tentacles', and 'weight(oz.) columns
pond = pd.DataFrame([{'type': 'Fried Egg', 'tentacles': 25, 'weight(oz.)': 1.05},
{'type': 'Fried Egg', 'tentacles': 23, 'weight(oz.)': 0.99},
{'type': 'Fried Egg', 'tentacles': 23, 'weight(oz.)': 0.84},
{'type': 'Fried Egg', 'tentacles': 25, 'weight(oz.)': 0.83},
{'type': 'Fried Egg', 'tentacles': 21, 'weight(oz.)': 1.00},
{'type': 'Upside-Down', 'tentacles': 8, 'weight(oz.)': 4.12},
{'type': 'Upside-Down', 'tentacles': 10, 'weight(oz.)': 6.93},
{'type': 'Upside-Down', 'tentacles': 8, 'weight(oz.)': 4.99},
{'type': 'Cannonball', 'tentacles': 16, 'weight(oz.)': 22.8},
{'type': 'Cannonball', 'tentacles': 17, 'weight(oz.)': 21.0},
{'type': 'Cannonball', 'tentacles': 16, 'weight(oz.)': 19.86},
{'type': 'Cannonball', 'tentacles': 15, 'weight(oz.)': 22.37},
{'type': 'Cannonball', 'tentacles': 15, 'weight(oz.)': 21.09},
{'type': 'Cannonball', 'tentacles': 16, 'weight(oz.)': 22.03},
{'type': 'Helmet', 'tentacles': 12, 'weight(oz.)': 19.04},
{'type': 'Helmet', 'tentacles': 12, 'weight(oz.)': 19.73},
{'type': 'Helmet', 'tentacles': 12, 'weight(oz.)': 19.20}])
pond
```

type | tentacles | weight(oz.) | |
---|---|---|---|

0 | Fried Egg | 25 | 1.05 |

1 | Fried Egg | 23 | 0.99 |

2 | Fried Egg | 23 | 0.84 |

3 | Fried Egg | 25 | 0.83 |

4 | Fried Egg | 21 | 1.00 |

5 | Upside-Down | 8 | 4.12 |

6 | Upside-Down | 10 | 6.93 |

7 | Upside-Down | 8 | 4.99 |

8 | Cannonball | 16 | 22.80 |

9 | Cannonball | 17 | 21.00 |

10 | Cannonball | 16 | 19.86 |

11 | Cannonball | 15 | 22.37 |

12 | Cannonball | 15 | 21.09 |

13 | Cannonball | 16 | 22.03 |

14 | Helmet | 12 | 19.04 |

15 | Helmet | 12 | 19.73 |

16 | Helmet | 12 | 19.20 |

#### Example 5 Solution:

**Total Jellyfish in the pond: 17**

###### Hand Calculations:

P(Fried Egg) = 5⁄17 = 0.2941

P(Cannonball) = 6⁄17 = 0.3529

Notice that in this question, (NAME) can't be stung by two jellyfish at once, so the two events are mutually exclusive.

In other words, P(Fried Egg and Cannonball) = 0.

We can then calculate:

`P(Fried Egg or Cannonball) = 0.2941 + 0.3529 = 0.647`

###### Python Calculations:

# Example 6: What's for Lunch? (with Python)

A group of 20 friends are trying to decide what to order for lunch. Five of the friends want to eat at Cheesecake Factory, eight of the friends want to eat at Counter, and the remaining seven want to eat at McDonald's. To fairly decide, the friends decide to put 20 slips of paper into a hat, each slip representing one friend's chosen restaurant.

Below is a DataFrame representing all the pieces of paper in the hat:

```
# Creating a DataFrame called 'hat' with a 'restaurant' column
hat = pd.DataFrame([{'restaurant': 'Cheesecake Factory'},{'restaurant': 'McDonalds'},{'restaurant': 'Counter'},
{'restaurant': 'McDonalds'},{'restaurant': 'Cheesecake Factory'},{'restaurant': 'Cheesecake Factory'},
{'restaurant': 'Counter'},{'restaurant': 'Cheesecake Factory'},{'restaurant': 'McDonalds'},
{'restaurant': 'Counter'},{'restaurant': 'Counter'},{'restaurant': 'McDonalds'},
{'restaurant': 'Counter'},{'restaurant': 'McDonalds'},{'restaurant': 'Counter'},
{'restaurant': 'McDonalds'},{'restaurant': 'Cheesecake Factory'},{'restaurant': 'Counter'},
{'restaurant': 'McDonalds'},{'restaurant': 'Counter'}])
hat
```

restaurant | |
---|---|

0 | Cheesecake Factory |

1 | McDonalds |

2 | Counter |

3 | McDonalds |

4 | Cheesecake Factory |

5 | Cheesecake Factory |

6 | Counter |

7 | Cheesecake Factory |

8 | McDonalds |

9 | Counter |

10 | Counter |

11 | McDonalds |

12 | Counter |

13 | McDonalds |

14 | Counter |

15 | McDonalds |

16 | Cheesecake Factory |

17 | Counter |

18 | McDonalds |

19 | Counter |

One slip will be randomly selected as the winning restaurant for lunch.

What is the probability that Cheesecake Factory or Counter is selected?

#### Example 6 Solution:

**P(Cheesecake Factory) = 5⁄20 = 0.25**

###### Hand Calculations

P(Counter) = 8⁄20 = 0.4

Notice that these are mutually exclusive: two restaurants can't be chosen at the same time. In other words, P(Cheesecake Factory and Counter) = 0.

We can then calculate:

`P(Cheesecake Factory or Counter) = 0.25 + 0.4 = 0.65`

###### Python Calculations

# Example 7: Is a Hotdog a Sandwich? (with Python)

In a small survey, 32 people responded to the question "Is a hotdog a sandwich?".

- 50% of the respondents were female and the rest were male.
- 11 people responded with 'yes' and 21 responded with 'no'.
- Of the female participants who took the survey, 5 responded with 'yes'.

Below is a DataFrame representing all the responses to the survey:

```
# creating a Dataframe named 'survey' with 'gender' and 'response' columns
survey = pd.DataFrame([{'gender': 'female', 'response': 'no'}, {'gender': 'male', 'response': 'yes'}, {'gender': 'female', 'response': 'no'},
{'gender': 'female', 'response': 'yes'}, {'gender': 'female', 'response': 'no'}, {'gender': 'female', 'response': 'no'},
{'gender': 'male', 'response': 'no'}, {'gender': 'female', 'response': 'no'}, {'gender': 'male', 'response': 'no'},
{'gender': 'male', 'response': 'yes'}, {'gender': 'male', 'response': 'yes'}, {'gender': 'male', 'response': 'no'},
{'gender': 'female', 'response': 'no'}, {'gender': 'female', 'response': 'no'}, {'gender': 'male', 'response': 'no'},
{'gender': 'female', 'response': 'yes'}, {'gender': 'male', 'response': 'yes'}, {'gender': 'female', 'response': 'no'},
{'gender': 'male', 'response': 'yes'}, {'gender': 'male', 'response': 'yes'}, {'gender': 'female', 'response': 'no'},
{'gender': 'male', 'response': 'no'}, {'gender': 'female', 'response': 'no'}, {'gender': 'female', 'response': 'yes'},
{'gender': 'female', 'response': 'yes'}, {'gender': 'male', 'response': 'no'}, {'gender': 'male', 'response': 'no'},
{'gender': 'male', 'response': 'no'}, {'gender': 'female', 'response': 'no'}, {'gender': 'male', 'response': 'no'},
{'gender': 'male', 'response': 'no'}, {'gender': 'female', 'response': 'yes'}])
survey
```

gender | response | |
---|---|---|

0 | female | no |

1 | male | yes |

2 | female | no |

3 | female | yes |

4 | female | no |

5 | female | no |

6 | male | no |

7 | female | no |

8 | male | no |

9 | male | yes |

10 | male | yes |

11 | male | no |

12 | female | no |

13 | female | no |

14 | male | no |

15 | female | yes |

16 | male | yes |

17 | female | no |

18 | male | yes |

19 | male | yes |

20 | female | no |

21 | male | no |

22 | female | no |

23 | female | yes |

24 | female | yes |

25 | male | no |

26 | male | no |

27 | male | no |

28 | female | no |

29 | male | no |

30 | male | no |

31 | female | yes |

What is the probability that a randomly selected respondent from the survey is female or said that a hotdog *is* a sandwich?

#### Example 7 Solution:

**P(female) = 0.5**

###### Hand Calculations:

P(yes) = 11⁄32 = 0.3438

P(female and yes)

= P(yes | female) * P(female)

= 5⁄16 * 0.5 = 0.1563

We can then calculate:

`P(female or yes)`

= 0.5 + 0.34375 - 0.15625

= 0.6875

###### Python Calculations:

A detailed explanation of the multiplication rule is part of the DISCOVERY course content: