Answered step by step
Verified Expert Solution
Link Copied!

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:

  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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the use of bootstrap program?

Answered: 1 week ago

Question

What is a process and process table?

Answered: 1 week ago

Question

What is Industrial Economics and Theory of Firm?

Answered: 1 week ago