Quick Review
Let's review some important concepts that you might need for this next project.
Suppose you have an unfair die that comes up according to these probabilities:
Die Face (min) | Probability |
---|---|
1 | 0.15 |
2 | 0.25 |
3 | 0.1 |
4 | 0.1 |
5 | 0.35 |
6 | 0.05 |
Recall that we could use conditional statements to simulate this:
Also recall a shortcut for doing this instead:
Suppose we wanted to turn this work into a function called roll_die_n_times
that takes in the die faces, the probabilities of each face, and the number of times that you want to roll the dice and returns a list containing the die rolls. We could do that here:
What if we wanted to return the average face value that comes up? We could actually create a new function called average_die
that calls our previous function roll_die_n_times
.
Suppose we want to roll the die 100 times and plot a histogram of the die faces that come up.
What if we wanted to plot the simulation number versus the face value? For that, we would need to store another list containing the the simulation numbers. If we want to run this simulation 10 times, we'll want to store the numbers 1 through 10. There are a few ways to do this. Firstly, you can use a for loop.
Or you could condense this using a list comprehension:
Now, we can create a scatterplot of simulation number versus die face:
Directions...read the Bank Project carefully with your partner. Do NOT start coding. You should just be jotting down ideas, questions, and patterns with pencil and paper for a while.