Hello,
I am trying to submit my solution for the Probability_Calculator problem for the past 3 hours but i’ve come to a dead end, since for example on some tests, the method: hat.draw(2) is used and [“blue”, “red”] is expected, but actual is not only that since drawn balls are random, so sometimes we would have something like [“blue”, “blue”] or [“red”, “red”] etc. So, how can my code pass the cases, since on each execution we have different results, but grader demands a specific one.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.73
It appears that if i also import the seed in my code it prints the fixed results wanted by the grader, but by submitting it without the seed (as suggested) it doesn’t return fixed results.
I only wrote the program in probability_calculator.py. However, i watched the structure of main.py and in the beggining it has the line random.seed(95), which if i also import on my text editor (not on replit) prints the expected results.
Hello, there are 2 test cases which supposedly are not correct, but they return correct results while running locally. Is there any chance you could help with the submission?
def draw(self, balls):
if(balls > len(self.contents)):
for content in self.contents:
self.removed.append(content)
self.contents = []
else:
for i in range(balls):
to_be_removed = random.choice(self.contents)
self.removed.append(to_be_removed)
self.contents.remove(to_be_removed)
return self.removed
This is not how you were told to reset the contents of the hat.
This method should remove balls at random from contents and return those balls as a list of strings. 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.
fake_hat.contents.append(drawn_ball) #insert them so they can be re-removed in next loop
Reaching into the private data members of an object is a huge red flag. Do not do this. Instead you need to draw from a fresh copy of the hat each time.
Regarding the markdown paragraph, I had decided to draw balls one-by-one since that’s what I thought would give some meaning to this phrase: “The balls should not go back into the hat during the draw, similar to an urn experiment without replacement.” However, after you suggestion I changed the draw method by using the random.sample() method and removing the “removed” instance variable. In addition to that, I create a new hat object in every loop, but I still have problems in the submission.