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:

import pandas as pd
Importing 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
typetentaclesweight(oz.)
0Fried Egg251.05
1Fried Egg230.99
2Fried Egg230.84
3Fried Egg250.83
4Fried Egg211.00
5Upside-Down84.12
6Upside-Down106.93
7Upside-Down84.99
8Cannonball1622.80
9Cannonball1721.00
10Cannonball1619.86
11Cannonball1522.37
12Cannonball1521.09
13Cannonball1622.03
14Helmet1219.04
15Helmet1219.73
16Helmet1219.20
Creating a Dataframe of Jellyfish
Tired fom her hike up the mountain, Karen decides to ignore the sign and instead take a relaxing swim in the pond. Of course, she's guaranteed to get stung by a jellyfish. What is the probability that Karen is stung by either a Fried Egg Jellyfish or a Cannonball Jellyfish?

Example 5 Solution:

Hand Calculations:
Total Jellyfish in the pond: 17
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:
# probability of getting stung by a Fried Egg Jellyfish
prob_fried_egg =len(pond[pond['type'] == 'Fried Egg']) / len(pond)

# probability of getting stung by a Cannonball Jellyfish
prob_cannonball = len(pond[pond['type'] == 'Cannonball']) / len(pond)

# probability of getting stung by both a Fried Egg and Cannonball Jellyfish
prob_both = len(pond[(pond['type'] == 'Fried Egg') & (pond['type'] == 'Cannonball')]) / len(pond)

# answer
prob_fried_egg_or_cannonball = prob_fried_egg + prob_cannonball - prob_both

prob_fried_egg_or_cannonball

0.6470588235294118

Finding P(Fried Egg or Cannonball)


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
0Cheesecake Factory
1McDonalds
2Counter
3McDonalds
4Cheesecake Factory
5Cheesecake Factory
6Counter
7Cheesecake Factory
8McDonalds
9Counter
10Counter
11McDonalds
12Counter
13McDonalds
14Counter
15McDonalds
16Cheesecake Factory
17Counter
18McDonalds
19Counter
Creating A DataFrame of Restaurants on Pieces of Paper

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:

Hand Calculations
P(Cheesecake Factory) = 5⁄20 = 0.25
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
prob_cheesecake_or_counter = len(hat[(hat['restaurant']== 'Cheesecake Factory')  | (hat['restaurant'] == 'Counter')]) / len(hat)
prob_cheesecake_or_counter

0.65

Using Conditionals to Calculate P(Cheesecake Factory or Counter


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
genderresponse
0femaleno
1maleyes
2femaleno
3femaleyes
4femaleno
5femaleno
6maleno
7femaleno
8maleno
9maleyes
10maleyes
11maleno
12femaleno
13femaleno
14maleno
15femaleyes
16maleyes
17femaleno
18maleyes
19maleyes
20femaleno
21maleno
22femaleno
23femaleyes
24femaleyes
25maleno
26maleno
27maleno
28femaleno
29maleno
30maleno
31femaleyes
Creating a DataFrame of Survey Responses

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:

Hand Calculations:
P(female) = 0.5
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:
prob_female_or_yes = len(survey[(survey['gender'] == 'female') | (survey['response'] == 'yes')]) / len(survey)
prob_female_or_yes

0.6875

Using Conditionals to Calculate P(female or answered yes)

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