Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
- you can generate random birthdays with the randint function in the random module.
- For simplicity, use the day number of the year, not the actual date
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started