The birthday paradox is based on a counter-intuitive fact that in any class of 23 students or more, there is a higher probability of having at least two students sharing the same bithday.

Considering that there are 366 different possible dates in a year (leap year), you may first predict that it would take a group of 183 students (50% of 366) to reach a 50% probability of at least two students sharing the same birthday. However this prediction would be wrong as this is not how the probabilities work in this case. You can use this page to find out more how to work out that with a class size of only 23 students, there is a probability of 50% that at least two students sharing the same birthday.

#### Python Challenge

For this Python challenge we will create a statistical simulation program to test the Birthday Paradox. Our aim is to determine whether the actual probabilities match the predicted probabilities by showing that, with a group of 23 students or more, the probability of having at least two students sharing the same birthday will be at least 50%.

We have started a program to help you with this challenge (See trinket window below). So far our program will:

- Generate a class list of students (e.g. 23 students or more)
- Use a
*randomDate()*function to generate random birthdays for each of our students - Store the lists of birthdays in a list
- Output the list of students with their randomly generated birthdays

Your task is to complete this code to:

- Work out if, in this list of students, at least two students share the same birthday, and if so output their names and birthdays.

You will then be able to run this code several time to check whether, with a group of 23 students or more, you obtain a 50% or above chance of having at least two students sharing the same birthday. Note that you could also get the program to automatically repeat the experiment several times and calculate the resulting statistic (e.g. out of 10 experiments).

Below is the code to complete…

#### Solution...

The solution for this challenge is available to full members!Find out how to become a member:

➤ Members' Area