Question: Birthday problem in Python: Write a function called has_duplicates() , that takes a list and returns True if there is any element that appears more

Birthday problem in Python:

Write a function called has_duplicates(), that takes a list and returns True if there is any element that appears more than once. It should not modify the original list.

If there are 45 students in the class, what are the chances that any two students will have the same birthday? You can estimate this probability by generating random samples of 45 birthdays and checking for matches.

Hints:

  1. you can generate random birthdays with the randint function in the random module.
  2. For simplicity, use the day number of the year, not the actual date
  3. you can use the book solution as a starting point for this assignment: https://github.com/AllenDowney/ThinkPython2/blob/master/code/birthday.py or http://greenteapress.com/thinkpython2/code/birthday.py

The code should print out:

  • number of students
  • number of iterations/samples
  • list of duplicate days for each iteration, where duplicates are found
  • probability

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!