I have a problem with probability calculator and can't find a solution

Hi everyone, I have the probability near 0.45 and do not know where is a mistake

Here is my code

import copy
import random


class Hat:
    def __init__(self, **balls):
        self.contents = []
        for k in balls.keys():
            for v in range(0,balls.get(k)):
                self.contents.append(str(k))

    def draw(self, amount):
        pulled_balls = []
        if amount > len(self.contents):
            self.contents.extend(pulled_balls)
        else:
            for n in range(0, amount):
                contentslenght = len(self.contents)
                randomnumber = random.randint(0, contentslenght - 1)
                pulled_balls.append(self.contents[randomnumber])
                self.contents.remove(self.contents[randomnumber])
            return pulled_balls


def experiment(hat, expected_balls, num_balls_drawn, num_experiments):

      m = 0
      n = 0
      for r in range(num_experiments):
          expected = list()
          balls = copy.deepcopy(hat)
          allballs = balls.draw(num_balls_drawn)
          for v,k in expected_balls.items():
              expected += k * [v]


          if(all(item in allballs for item in expected)):
             m += 1
          n += 1

      print(expected)
      print(allballs)
      print(m)
      probability = m / n
      return probability

Error message :

all(item in ["green", "blue"] for item in ["green", "green"]) is True.
You can’t compare the two lists with that line.

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