Get startedGet started for free

Exercise 5. American Roulette average winnings per bet

Now create a random variable \(Y\) that contains your average winnings per bet after betting on green 10,000 times.

This exercise is part of the course

HarvardX Data Science - Probability (PH125.3x)

View Course

Exercise instructions

  • Run a single Monte Carlo simulation of 10,000 bets using the following steps. (You do not need to replicate the sample code.)
  • Specify n as the number of times you want to sample from the possible outcomes.
  • Use the sample function to return n values from a vector of possible values: winning $17 or losing $1. Be sure to assign a probability to each outcome and indicate that you are sampling with replacement.
  • Calculate the average result per bet placed using the mean function.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Use the `set.seed` function to make sure your answer matches the expected result after random sampling.
set.seed(1)

# Define the number of bets using the variable 'n'
n <- 10000

# Assign a variable `p_green` as the probability of the ball landing in a green pocket
p_green <- 2 / 38

# Assign a variable `p_not_green` as the probability of the ball not landing in a green pocket
p_not_green <- 1 - p_green

# Create a vector called `X` that contains the outcomes of `n` bets


# Define a variable `Y` that contains the mean outcome per bet. Print this mean to the console.
Edit and Run Code