FAQ: Introduction to Data Science - Probability

This community-built FAQ covers the “Probability” exercise from the lesson “Introduction to Data Science”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Code Foundations

FAQs on the exercise Probability

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

1 Like

I have zero knowledge of scientific probability so it may be just me, but on a purely common-sense level the result of this script feels completely counter-intuitive:
If there are 365 possible unique birth dates and there are 90 people in the room (i.e. 1/4 of the number of unique birthdates), how can the probability of two of them having the same birthday be “nearly 100%”?

Moreover, why does the script return an error if I enter a number of people higher than 120?


This is a well known problem called the birthday paradox.

When there are 23 people in a room, the probability of two having the same birthday is roughly 0.5. That number goes up quickly as more and more people enter the room. With 90 people in the room the chance of no two having the same birthday is very small, about 0.00002. So the probability that at least two people have the same birthday is 1 - 0.00002 which is still very close to 1.

>>> 90 * 89 / 2
>>> (364/365) ** 4005
>>> 1 - (364/365) ** 4005
1 Like

I was wondering, in the code for this exercise the “simulate” function comes earlier in the code than the “calculate_probability” and the “find_duplicates” functions even though “simulate” uses these functions in its body. Does python care about the order of the function definitions in its code?


Hi @laggedinertia,

See the following:

def func_one(m):
    return func_two(m) * 2

def func_two(n):
    return n * 7


It is fine for func_one to include a call to func_two, even though func_two was not yet defined, so long as func_two gets defined before that calling statement actually executes.

Neither of the above functions executes until this statement calls func_one:


Therefore, by the time the statement in func_one that calls func_two gets executed, func_two has been defined.

By contrast, this raises a NameError because the call to func_two attempts to execute before func_two has been defined:

def func_one(m):
    return func_two(m) * 2


def func_two(n):
    return n * 7

I have the same question.

The reason is in the error message…

OverflowError: int too large to convert to float.

365 ** 121



Is it possible that this calculation is a bit wrong?
Because the possibility that a day in february is choosen is as high as a month in in june is choosen.

Welcome to the forums!

There are 28 days in February (29 in a leap year) and 30 days in June. Therefore, the probability of choosing a certain day in February is 1/28 or 1/29, while the probability of choosing a certain day in June is lower, 1/30.

Erm, 28/365 or 29/366 is lower than 30 or 31 over either 365 or 366.

The Birthday Paradox concerns itself with the number of people in the room, not the number of days in the year.

Yes, my bad. A big mistake on my part as I expressed it wrongly.

1 Like