I am trying to write a code for class that identifies the probability that two or more people given can have the same birthday out of a group by running this experiment 10^6 times and then calculating the fraction of times during which two or more people had the same birthday. I attached the code below, but when I try and run it absolutely nothing happens. It gives no error message, it just stops working. Does anyone have an idea why?
-
import random
def calc_birthday_probability (num_people):
random.seed (2020) # Don't change this value
num_trials = 1000000
probability = 0
list1 = []
num_people = int(input())
repeats = 0
for i in range(0,num_trials+1):
for i in range (0,num_people+1):
list1.append(random.randint (1,3655))
for i in list1:
if list1.count(i)>1:
repeats +=1
i = i+1
i = i+1
prob = repeats//num_trials
probability = probability + prob
return probability
a = calc_birthday_probability(10)
print(a)
Aucun commentaire:
Enregistrer un commentaire