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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

Trace the evolution of the marketing concept.

Answered: 1 week ago

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

Question

b. Why were these values considered important?

Answered: 1 week ago