Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

extend your Python simulation over multiple trials by embedding your code into a for loop over the number of trials desired, say 100, 1000 or

extend your Python simulation over multiple trials by embedding your code into a for loop over the number of trials desired, say 100, 1000 or 1000. Again, let the user specify the number of people in the room. Estimate the probability of having the same birthday as yours by counting the number of times a birthday match occurred, over the number of trials.

Heres my Code:

import random 
 
nPeople = int(input("How many people are in the room: ")) 
birthday=random.randint(1,365) 
 
nSuccess=0; nTrials=0; 
while True: 
 strRun = str(input("Run Trial? y/n ")) 
 if strRun.lower()=="y": 
 nTrials=nTrials+1 
 print("Running trial #: ",nTrials) 
 roomBirthdays=[random.randint(1,365) for _ in range(nPeople)] 
 if birthday in roomBirthdays: 
 nSuccess=nSuccess+1 
 print("Number of Matches: {0}".format(nSuccess)) 
 print("Probability of someone sharing your birthday for a room of {0}: {1:.2f}".format(nPeople,float(nSuccess)/nTrials)) 
 elif strRun.lower()=="n": 
 break 

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

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions