Write a program that receives a number n of people and an x number of repetitions and draws lists with birthday dates, and checks if there is any matching date. For each loop one must re-sort the lists, and for each list where there are coincident cases one should add 1 to the number of favorable cases. After rotating the x loops of the percentage of times that there were coincident anniversaries.
Detail: Use list compression to generate birthday dates
Solution Attempt:
import random
datas =[x for x in range(1,366)]
#print(datas)
n = int(input("Digite o número de pessoas: "))
x = int(input("Digite o número de repetições: "))
datas_sorteadas = []
favoraveis = 0
for i in range(x):
for i in range(n):
datas_sorteadas.append(random.choice(datas))
print(datas_sorteadas)
for data in datas_sorteadas:
if datas_sorteadas.count(data)>=2:
favoraveis +=1
datas_sorteadas = []
datas_sorteadas.append(random.choice(datas))
print(datas_sorteadas)
print("Casos Favoráveis: ", favoraveis)
print("n*x",n*x)
print("Percentual: ", (favoraveis/(n*x)))
#print(datas_sorteadas)
The program is running without errors but I suspect it is not correct. The results do not fit the theory. Any ideas on how to fix it?