prob_matches = []
num_people = [2,80]
def birthday_sim(num_people , num_sims = 1000):
possible_birthdays = [i for i in range(0,365)]
for party in range(num_sims):
birthdays = pd.Series(random.choices(possible_birthdays, k=num_people))
prob_matches.append('Match') if birthdays.nunique() < num_people else prob_matches.append('No Match')
return prob_matches.count('Match')/len(prob_matches)
# Test: if 20 people are in a room, what is the approximate probability
# that at least two of them share a birthday?
birthday_sim(num_people = 80)
birthday_problem_df = ['prob_matches', 'num_people']
birthday_problem_df
The problem is to solve the birthday paradox and create a dataframe with one column as number of people in a class and the other problem as probability of sharing a birthday?
The two columns need to be derived from two lists ['prob_matches] and ['num_people'] that are in the defined function. The 'num_people' list refers to the number of people in the class and the 'prob_matches' indicates the odds of people sharing a birthday. My range of people is 2 to 80.
I am wondering what errors I am making in my above code?
You need to move this list initialization
prob_matches = []into your function:Then you can do