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
Research the significance of the UNIX core of macOS and write a few sentences describing your findings.
aniked [119]

Answer:

The Unix core used in Apple's macOS is called Darwin which is similar to the BSD Unix operating system. The Darwin in macOS has evolved, providing a slick aqua-graphical user interface for users to interact with the application by clicking rather than writing Unix commands in terminals.

Explanation:

The macOS is the operating system used by Apple computer brands. The operating system is a subset of the Unix's BSD operating system. It still makes use of the traditional Unix terminal and scripts but with a few alterations.

4 0
3 years ago
PLEASE HELP SOMEONE!!!!!!!!! WILL GIVE BRAINLIEST!!!!!!!!!!!!!!!!!!!!!!!!! Fill in the blanks.
olasank [31]
<span> change the behavior of the program I think</span>
7 0
4 years ago
Write a MATLAB script using the quiver and contour commands to visualize the field and its divergence. Assume the region of inte
DochEvi [55]

Answer:

2b2t

Explanation:

2b2t

4 0
3 years ago
The process of finding the largest and smallest numbers is used frequently in computer applications. Write a C++ program that us
WINSTONCH [101]

Answer:

The program to this question can be given as:

Program:

#include<iostream>  //header file

using namespace std;

int main()    //main method

{

int x[10],i,largest = 0,second_largest=0,n;  //variable

cout << "Enter Number of elements :";  //message

cin>>n;

cout << "Insert array elements :";  //message

for(i=0;i<n;i++)  //insert elements in array

{

cin >>x[i];

}

//Finding Largest element  

for(i=0;i<n;i++)

{

if (x[i]>largest)

{

largest = x[i];

}

}

//finding second largset element

for(i=0;i<n;i++)

{

if (x[i]>second_largest)

{

   if(x[i]==largest)

   {

   continue;   //Ignoring largest in order to get second largest

   }

   second_largest=x[i];

}

}

//print value

cout <<"Largest Number:"<<largest<<endl;

cout <<"Second Largest Number:"<<second_largest;

return 0;

}

Output:

Enter Number of elements :5

Insert array elements :33

45

75

87

23

Largest Number:87

Second Largest Number:75

Explanation:

In the above program firstly we define the header file then we define the main method in the main method we define the array and other variables. We first input the number for the size of the array. Then we insert array elements after inserting array elements we search the largest number and the second largest number in the array. To search the largest number in the array we use the loop. To search the first largest number we define a condition that array is greater than the largest number and store the value into the largest variable. Then we check the second largest number in the array for this we use two conditions that are array is greater than the second largest number in this we use another condition that is array is equal to the largest number. If the inner condition is true then it will move forward and end of an inner condition. In the outer condition, the value will be stored on the second_largest variable all the conditions will be done inner the loop. At the last we print values.

3 0
3 years ago
When _______ wordart, you need to consider both the font size of the text and the size of the text box that contains wordart?
padilas [110]
The correct answer is resizing. If you're making a logo and creating wordart. you have to care about resizing because the art needs to be clearly visible and appealing no matter the size. If you place it in a box, you have to care that it doesn't go over the edges of the box or anything similar that might seem appalling.
4 0
4 years ago
Other questions:
  • What are the four basic operating principles of the information processing cycle?
    7·2 answers
  • Which programming component provides a temporary, named storage location in computer memory that cannot change during program ex
    6·1 answer
  • What is illegal to search on the internet?
    5·1 answer
  • Which option allows you to add different effects for each of the bulleted items on your slide
    13·1 answer
  • How do you choose the amount of points you give a person here on this brainless app...??.
    11·2 answers
  • 1. The best program to present numerical data in would be ____. a. Access c. PowerPoint b. Excel d. Word
    6·1 answer
  • An expression involving byte, int, and literal numbers is promoted to which of these?
    12·1 answer
  • ETC = 220,000 PV = 25,000 AC = 40,000. What is EAC? What does this calculation tell you?
    5·1 answer
  • I have a question involving do and for loops while using arrays.
    8·1 answer
  • refer to the exhibit. a user pc has successfully transmitted packets to www.cisco. which ip address does the user pc target in o
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!