Build a Probability Calculator Project - Build a Probability Calculator Project

Tell us what’s happening:

The issue is :

// running tests
4. The experiment method should return a different probability.
// tests completed
// console output
0.213
0.207
.

Ran 1 test in 0.000s

OK

But I don’t know what to fix because they precised “Do not initialize random seed within the file.”

Your code so far

import copy
import random

class Hat:
    #random.seed()

    def __init__(self, **kwargs):
        lists_list = [list(color for _ in range(number)) for color, number in kwargs.items()]
        self.contents = [item for sublist in lists_list for item in sublist]
        #print(self.contents)
    
    def draw(self, number):
        balls_total = min(number, len(self.contents))
        #print(balls_total)
        result= [self.contents.pop(random.randrange(len(self.contents))) for _ in range(balls_total)]
        #print(result)        
        #print(self.contents)
        return result

def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
    M = 0
    expected_balls_len = len(expected_balls)
    for i in range(num_experiments):
        balls = copy.deepcopy(hat)
        choiced_balls = balls.draw(num_balls_drawn)
        drawn_balls = {color: choiced_balls.count(color) for color in choiced_balls}
        #print(drawn_balls)
        shared_balls = {color: drawn_balls[color] for color in drawn_balls if color in expected_balls and drawn_balls[color] == expected_balls[color]}
        #print(shared_balls)
        if len(shared_balls) == expected_balls_len:
            M += 1
    #print(M)
    return round(M / num_experiments, 3)


hat0 = Hat(red=2, blue=1)
hat0.draw(6)
hat1 = Hat(yellow=3, blue=2, green=6)
hat2 = Hat(red=5, orange=4)
hat3 = Hat(red=5, orange=4, black=1, blue=0, pink=2, striped=9)
hat = Hat(black=6, red=4, green=3)
probability = experiment(hat=hat,
                  expected_balls={'red':2,'green':1},
                  num_balls_drawn=5,
                  num_experiments=2000)
print(probability)

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Build a Probability Calculator Project - Build a Probability Calculator Project

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/build-a-probability-calculator-project/5e44414f903586ffb414c950.md at main · freeCodeCamp/freeCodeCamp · GitHub

The fix is : use “greater than” (and not the equality).
code removed by moderator

Congratulations on solving the challenge! You should be proud of your achievement…we are! But we are removing your working solution, so it is not available to others who have not yet done the work to get there. Again, congrats!