Instruction: Work with a neighbor to answer the following questions. Solutions will be posted on the course website. To get started, download the class activity template file.
Previously, we consider the following gambling scenario:
Here is an R simulation to estimate the probability:
set.seed(279)
nsim <- 1000
results <- rep(0, nsim)
wheel <- c(rep("green", 2), rep("black", 18), rep("red", 18))
for(i in 1:nsim){
money <- 50 # starting money
while(money > 0 && money < 100){
spin <- sample(wheel, size = 1)
if(spin == "red"){
money <- money + 1
} else {
money <- money - 1
}
}
results[i] <- money == 100
}
mean(results)
## [1] 0.008
if...else...
statements.A valuable tool for translating code from one language to another is ChatGPT. This can be helpful when you are learning a new language, because it can help you explore fundamental syntax and functions. However, be careful: if you don’t know a language well, it can be hard to check whether ChatGPT’s answer is reasonable!