Lesson goal: Picking balls

Previous: The dice game of Craps | Home | Next: Rolling a dice, twice

Picking balls out of a box, containing a mixtures of different balls gives some interesting probability puzzles.

In this one, suppose a ball is picked from random from a box containing 6 red balls, 4 white balls, and 5 blue balls. Here are some questions: What is the chance the ball picked is red? blue? not red? red or white?

Here, we'll represent the box of balls as an array as shown in the code below by the balls = ... line. As usual, N will be the number of times you'd like to reset everything, and pick a ball. The varible gotit ("got it") will count the number of times you picked the ball whose color you wanted.

Now you try. Choose a value of N and edit the ?? to be a color ball you'd like to pick ("r", "w", or "b").

Type your code here:

See your results here: