1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
adelina 88 [10]
4 years ago
15

The birthday problem is as follows: given a group of n people in a room, what is the probability that two or more of them have t

he same birthday? It is possible to determine the answer to this question via simulation. Using the starting template provided to you, complete the function called calc birthday probability that takes as input n and returns the probability that two or more of the n people will have the same birthday. To do this, the function should create a list of size n and generate n birthdays in the range 1 to 365 randomly, inclusive of the end-points 1 and 365. It should then check to see if any of the n birthdays are identical. The function should perform this experiment 106 times and calculate the fraction of time during which two or more people had the same birthday. The function will be called as follows from your main program
Import random

def calc_birthday_probability (num_people):
num_tries = le6
num_duplicates = 0

""" FIXME: Complete this function to return the probability of num_people in the room having the same birthday. """

return num_duplicates/num_tries
def main ():
num_people = 10
p = calc_birthday_probability (num_people)

num_people = 20
p = calc_birthday_probability (num_people)

return

# Main program
if __name__ == "_main_":
random.seed (2020)
main ()
Computers and Technology
1 answer:
Julli [10]4 years ago
4 0

Answer:

import random

def calc_birthday_probability(num_people):

   num_tries = 1e6

   num_duplicates = 0

   tries = 0

   while tries < num_tries:

       total_birthday = {}

       for i in range(1, 366):

           total_birthday[i] = 0

       for count in range(num_people):

           birthday = random.randint(1, 365)

           if total_birthday[birthday] != 0:

               num_duplicates += 1

               break

           total_birthday[birthday] += 1

       tries += 1

   return num_duplicates/num_tries

def main():

   num_people = 10

   p = calc_birthday_probability (num_people)

   print(p)

   num_people = 20

   p = calc_birthday_probability (num_people)

   print(p)

   return

if __name__ == "__main__":

   random.seed(2020)

   main()

Explanation:

  • Run the loop until the value of tries is less than num_tries to do number of trials.
  • Run the loop to create the desired number of birthdays by generating random numbers.
  • Increase  the num_duplicates  variable by 1, if the birthday has  already occurred.
  • Lastly define and then call the main function.

You might be interested in
Describe the relative benefits of routing over a broadcast style of communication. Is routed traffic more secure than broadcasti
iren2701 [21]

Routing is process of selecting and establishing the routes that data packets take on their way to a particular destination (specific IP addresses). Broadcasting on the other hand is the simultaneous transmission of the same message to multiple recipients. In contrast to routing, broadcasting lacks the ability to direct packets to a specific address. When it comes to security, routing is not necessarily more secure than broadcasting. Without goof security protocols other users can read messages even if they aren't the recipient of the packet.

8 0
3 years ago
Which type of camera is self contained ​
trasher [3.6K]
I think it’s a Digital camera
3 0
3 years ago
Read 2 more answers
Would you agree that intelligent machines take the place of human beings in no time? explain
bekas [8.4K]

Answer:

I think that they are smarter than humans themselves, but we have to remember all A.I. has to be programmed and created by a man, therefore it has to be just as imperfect as one.

Explanation:

hope this helps. have a nice day!

3 0
3 years ago
To see what information is stored in ram, a cisco administrator would type this command
Grace [21]
<span>To see what information is stored in ram, a cisco administrator would type this command: </span>show running-config
8 0
3 years ago
The part of the computer that provides access to the internet is the
Anuta_ua [19.1K]
The modem is what provides a computer access to the internet, but it doesn't necessarily have to be hard wired to your device. I'd say either A or D, but D seems more plausible.
5 0
3 years ago
Other questions:
  • A small company connects data acquisition equipment to the serial port of a computer. The equipment user has reported that not a
    8·1 answer
  • In Python
    15·1 answer
  • Give an example of an if/else statment and a case statment that are equivalent. Your example should contain at least three choic
    5·1 answer
  • What is credibility in the often-used framework of quality criteria?
    9·1 answer
  • Consider the following definitions:public boolean someMethod (int[] list, int value){ int counter; boolean flag = false; for (co
    10·1 answer
  • A printer is displaying no images on its LED panel. What can a technician do to troubleshoot the situation? Choose two answers.
    6·1 answer
  • Java: which expression is evaluated first
    13·1 answer
  • Hattie uses the line of code num == 7 to assign the number 7 to the variable named num. What correction should be made?
    7·1 answer
  • "Automated Deployment" is one of the prerequisite for DevOps implementation.
    8·1 answer
  • This isn't an academic question, but it's a question about something I am consistently seeing on Brainly, so please don't delete
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!