Hey everybody,
I have an issue with the last test of the Probability Calculator. I’m off by a small margin and can’t figure out where it goes wrong.
Like you can see in my code in mt.py I printed both lists before and after the draws to find any mistakes. But at least in my draw function everything seems to work fine.
So maybe it’s my experiment function. But I don’t see anything.
Can anybody give me a hint please?
Not sure if this is it, but seems there might be a problem in your draws method regarding what happens if your draws exceed the number of balls in the hat… gonna leave it at that for now… let me know if you need further clarification.
I don’t get it. I looked at every line of code in debugging mode for an hour. I can’t find anything wrong with it. Furthermore, I made a copy of the draw method where I print every line, and it seems to work like I want it to. Since you said there might be something wrong happening when the hat becomes empty, I tried multiple different ways for copying the list for the refill. It seems like all of them work.
Help
Hi @eliaskirchner! I’m going to go through your code tomorrow and get back with you if no one else has posted something by then or you haven’t figured it out! Good luck until then!
If you want to catch the error, try it on a hat that doesn’t have enough balls to cover all your draws.
What I believe the problem is:
When you’re hat runs out of balls, instead of returning an array of all the balls that were in the hat, your code instead fills the hat back up, then proceeds with removing balls. Thats why the one test you are failing is the test where there are only 7 balls, but requested 20 draws.
Per the instructions: The balls should not go back into the hat during the draw, similar to an urn experiment without replacement. If the number of balls to draw exceeds the available quantity, return all the balls.
Also, when I originally looked over the code, you were only failing the one test… now it seems you are failing two. Something you must have changed between then and now… maybe something to do with how you delete draws from the hat as the failure said you didn’t reduce the numbers in the hat.
That’s what I do in the mt.py
I draw more balls then there are available.
import prob_calculator
prob_calculator.random.seed(95)
hat = prob_calculator.Hat(yellow=1,red=1,green=1)
hat.draw_with_print(4)
Here I pull more balls than there are in the hat. I print the lists self.content and draws in every round as well as the list self.content after it gets refilled.
And the result looks fine to me. Please check it out.
“When your hat runs out of balls, instead of returning an array of all the balls that were in the hat, your code instead fills the hat back up, then proceeds with removing balls.”
Maybe it’s because I’m not a native speaker, but I don’t see the difference in these two things.
When you’re hat runs out of balls, instead of returning an array of all the balls that were in the hat, your code instead fills the hat back up, then proceeds with removing balls. Thats why the one test you are failing is the test where there are only 7 balls, but requested 20 draws.
Per the instructions: The balls should not go back into the hat during the draw, similar to an urn experiment without replacement. If the number of balls to draw exceeds the available quantity, return all the balls.
He’s telling you that you are not supposed to make any more draws if you draw more balls than are available. You should NOT put the balls back into the hat. Instead, you should RETURN all the balls. Return, in this case doesn’t mean return the balls back into the hat, it means that the function needs to return the values of all the balls that are in the hat.
Wow, didn’t realize it might not be a mistake but rather a misunderstanding due to multiple definitions for the work ‘return’.
Like bsandma1 states, in this case, it doesn’t mean return all your balls into the hat and continue drawing, it means you should stop drawing , and that the return value for your function should be a list of all the balls that were in the hat.
OH my god, I can’t believe that was it! I’m so happy. It works and I finally passed the last test. Only took me a week or so
Thank you for your patience and help, I appreciate it.
Thanks for clearing up the confusion with RETURN (programming statement) and return (an English word like any other). But when are the balls supposed to be returned for the subsequent tests? Does the instruction imply that we return all the balls back to the hat after we RETURN the remaining balls or do we reset the hat back to factory settings?
P.S. Apologies for dredging up a 4-month-old post.
I do need a bit more clarification on what you’re asking though. Is your code not working properly? I would need to see your code and I would need to know where the confusion is in your specific code.
If you start a new topic then I’ll move to that topic and check it out!
Thanks for the help. I figured it out; the tests passed just fine. All good. What was not evident to me was that every experiment needed a fresh copy of the hat. I guess what tripped me up was the instruction about not putting the balls back into the hat; that led me to believe that subsequent draws (until the sufficiency failure) had to be done from an ever-decreasing pool of balls. But since a fresh copy of the hat was necessary at the start of every experiment, all that was irrelevant.