Given n number of people in a room, calculate the probability that any two people in that room have the same birthday (assume 365 days every year = ignore leap year). Answers should be two decimals unless whole (0 or 1) eg 0.05

Difficulty: introductory

Starter code:

def calculate_probability(n):
	

Solutions:
def calculate_probability(n):
    return round(1 - (364 / 365) ** (n * (n - 1) / 2), 2)

def calculate_probability(n, p=1):
    for i in range(n):
        p *= 365 - i
    return round(1 - p / 365**n, 2)

from math import factorial

def calculate_probability(n):
    return round(1 - factorial(365) / (factorial(365-n) * 365**n) if n < 365 else 1, 2)

def calculate_probability(n):
    count = 1
    for i in range(n):
        count *= (365-i)/365
    return round(1 - count, 2)

def calculate_probability(n):
    #your code here
    if n==0 or n==1:
        return 0
    elif n>=365:
        return 1
    else:
        t=365**n
        s=1
        c=0
        while c<n:
            s*=365-c
            c+=1
        return float('{:.2f}'.format((t-s)/t))


calculate_probability=lambda n,d=365,f=__import__('math').factorial:n>d or round(1-f(d)//f(d-n)/d**n,2)

from math import factorial as f
def calculate_probability(n):
    a = 1
    for x in range(n):
        a *= (365-x)/365
    return round(1-a, 2)

def calculate_probability(n):
    p=1
    for i in range(n):
        p=p*(365-i)
    return round(1-p/365**n,2)

def calculate_probability(n):
    
    year = 365
    numer = 1
    den = 365 ** n
    
    while n > 0:
        print(year)
        numer *= year
        n -= 1
        year -= 1
    
    return round((1 - (numer/den)) , 2)