I was doing the probability calculator project in python for scientific computing. I submitted it once and it passed all the test but I exited the page without saving the solution. Now, I can’t even pass the first test with the exact same code and the console shows preloading issues instead of actual test errors. This bug also only happens with this one specific project.
It would be very helpful if you posted your full code and a link to the project. Thanks
from copy import copy
from random import randint
class Hat:
def __init__(self, **kwargs):
self.contents = [
color for color, count in kwargs.items()
for _ in range(count)
]
def draw(self, num):
if num > len(self.contents):
draw_list = copy(self.contents)
self.contents = []
return draw_list
draw_list = []
for _ in range(num):
rand = randint(0, len(self.contents) - 1)
draw_list.append(self.contents.pop(rand))
return draw_list
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
success = 0
for _ in range(num_experiments):
success_flag = True
backup = copy(hat.contents)
results = hat.draw(num_balls_drawn)
results = {b: results.count(b) for b in results}
for ball, count in expected_balls.items():
if results.get(ball, 0) < expected_balls.get(ball):
success_flag = False
break
if success_flag:
success += 1
hat.contents = backup
return success / num_experiments
Here is the code. Probability calculator project and here is the link to the project. These are the error messages that show up on the console.
The resource at “[https://www.freecodecamp.org/static/Lato-Regular-77ca2742388f408c3be7d0ec3e7dc392.woff”](https://www.freecodecamp.org/static/Lato-Regular-77ca2742388f408c3be7d0ec3e7dc392.woff%E2%80%9D) preloaded with link preload was not used within a few seconds. Make sure all attributes of the preload tag are set correctly.
I even tried logging out, pasting this solution outside of my account and it worked, but then when I sign back in, all the test fails.
that warning doesn’t matter at all, you can ignore it.
Run the tests with the console open, you will see the errors you need to worry about.
For example:
python-test-evaluator.ts:177 PythonError: Traceback (most recent call last):
File "/lib/python311.zip/_pyodide/_base.py", line 468, in eval_code
.run(globals, locals)
^^^^^^^^^^^^^^^^^^^^
File "/lib/python311.zip/_pyodide/_base.py", line 310, in run
coroutine = eval(self.code, globals, locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<exec>", line 3, in <module>
File "/home/pyodide/test_module.py", line 8, in <module>
probability_calculator.random.seed(95)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'probability_calculator' has no attribute 'random'
uhhh, please do not change the imports, it looks like we need import random
as is for the tests to work
Oh hey it worked. Funny because my initial submissions went fine with from random import randint
. Anyways, thanks a lot for the help.