Sort by

recency

|

109 Discussions

|

  • + 0 comments
    num,den= map(int, input().split())
    k=int(input())
    p=num/den
    geodis=0
    for k in range(1,6):
        geodis+=((1-p)**(k-1))*p
    print(round(geodis,3))
    
  • + 0 comments
    n,d = map(float,input().split());k = int(input());p = n/d
    print(round(sum((1 - p)**i * p for i in range(k)),3))
    
  • + 0 comments

    I found the tutorial brining in negative binomials a bit confusing. Isn't a clean way to compute this simply that the probability of not producing a defect in n=5 rounds covers the only possibility other than a defect occurring during the first n=5 inspections?

    python n = 5; p = 1 / 3.0; q = 1.0 - p; print(f"{(1.0-q**n):.3f}")

    // or in C double p = 1.0/3.0; double q = 1 - p; printf("%.3f", 1 - pow(q, 5));`

  • + 0 comments
    #The formula for the geometric distribution probability: (P(X = k) = (1-p)^{k-1}p),
    # Define the probability of success on a single trial
    p = 1/3
    
    # Initialize the probability of finding the first defect in the first 5 inspections
    prob = 0
    
    # Loop over the first 5 inspections
    for k in range(1, 6):
      # Calculate the probability of finding the first defect on the k-th inspection
      prob_k = (1-p)**(k-1) * p
    
      # Add this probability to the total probability
      prob += prob_k
    
    # Print the final probability
    print(round(prob, 3))
    
  • + 0 comments
    p_defect_product = 1/3
    
    n = 5
    p_first_defect = 0
    for i in range(1, n+1):
        p_first_defect += pow((1 - p_defect_product), i-1)*p_defect_product
    
    print(round(p_first_defect, 3))