Monte Carlo simulation Python
Question: Question: You have a bucket with 3 red balls and 3 green balls. Assume that
once you draw a ball out of the bucket, you don't replace it. What is the
probability of drawing 3 balls of the same color?

Problem: My code always gives 0.0

    
    
    import random
    def noReplacementSimulation(numTrials):
        '''
        Runs numTrials trials of a Monte Carlo simulation
        of drawing 3 balls out of a bucket containing
        3 red and 3 green balls. Balls are not replaced once
        drawn. Returns the a decimal - the fraction of times 3 
        balls of the same color were drawn.
        '''
    
        for i in range(numTrials):
            hola=0
            b=['r','r','r','g','g','g']
            for a in range(3):
              ball=random.choice(b)
              b.remove(ball)
            if b[0]==b[1] and b[1]==b[2] and b[2]==b[0]:
                hola=hola+1
        return float(hola)/numTrials    
    


Answer: Your code _doesn't_ always return `0.0`, only most of the time. You reset

    
    
    hola=0
    

_inside the loop_ , so you can only end with either `hola == 0` or `hola ==
1`. You want

    
    
    hola=0
    for i in range(numTrials):
        # stuff here
    

instead.

PS: the question asks "What is the probability of drawing 3 balls of the same
color?" but you're checking whether the three balls which are _left_ are of
the same colour. Those won't be the same in general.

