We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#The formula for the geometric distribution probability: (P(X = k) = (1-p)^{k-1}p),# Define the probability of success on a single trialp=1/3# Initialize the probability of finding the first defect in the first 5 inspectionsprob=0# Loop over the first 5 inspectionsforkinrange(1,6):# Calculate the probability of finding the first defect on the k-th inspectionprob_k=(1-p)**(k-1)*p# Add this probability to the total probabilityprob+=prob_k# Print the final probabilityprint(round(prob,3))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 4: Geometric Distribution II
You are viewing a single comment's thread. Return to all comments →