Homework 0: getting up to speed¶
Instructions: Please answer the following questions and submit your work by editing this jupyter notebook and submitting it on Canvas. Questions may involve math, programming, or neither, but for any you should make sure to explain your work: i.e., you should always have a cell with at least a few sentences explaining what you are doing.
1. Goat, please¶
I have two chickens and one goat, and am going to give one to you, but you have to pick randomly. We have three barn stalls that you can't see in, and I put one animal in each stall, in a randomly chosen order. Let us suppose that you would like to get a chicken (the goat won't fit in your apartment). You then pick a stall. Then, I open one of the other stalls that has a chicken in it (I can always do this), and remove that chicken. Now, you have the choice of either taking what's in the stall you originally picked, or taking what's in the other (as yet unopened) stall.
(a) First, decide whether you'd like to switch stalls in the last step or not.
Then, write python code to simulate from this procedure.
The code should explicitly represent what happens (e.g., which animal is in which stall),
and produce either "chicken"
or "goat"
, corresponding to which animal you get in the end.
(b) Use your code to simulate at least 10,000 times. Report how often you get a chicken.
Reminder: To get random values you probably want to use these methods:
import numpy as np
rng = np.random.default_rng()
u = rng.uniform(size=1)
k = rng.choice([0, 1, 2])
print(f"Here is a random number between 0 and 1: {u} and a random integer in (0, 1, 2): {k}")
Here is a random number between 0 and 1: [0.60572638] and a random integer in (0, 1, 2): 1