Scientific Computing with Python - Probability Calculator

I am trying to complete the Probability Calculator and I have completed the first 2 tests but the third test involving the experiment function will not work. Here is the link to my code. Can somebody help?
Thanks in advance

Good day SPARKSCoder,

There is a problem with your probability calculation.
what is the purpose of: desired += 1/len(drawn)

You only need to increase desired if all the expected balls is in the hat

I have tried that and updated my Repl but the probability is still higher

Just read through your code carefully, for example your if all(l): will always be true, thus your probability will be wrong.

Use the list length for your checks. If the length of the expected matches the length of the matched balls drawn, increase your desired counter

It still does not work

There are numerous problems:

  1. You are iterating over drawn while removing elements from it. Every time you remove something, you will skip something else.
  2. You are testing whether each of the drawn balls is among the expected balls. You should be testing whether all of the expected balls are among the drawn balls. You have it backward.
  3. Your draw method returns the wrong value sometimes. This will cause fail the next part of the test.
1 Like

It worked. Thank you so much.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.