## Exercise: Probability of Red, Green, and Black

Calculate the probability of landing on green, red, and black.

How can the `RouletteSpin()`

function be used to compute or approximate these probabilities?

## Exercise: Simulation Questions - Part 2

Now what happens if we:

run the simulation again with the same number of trials?

run the simulation with more trials, say 1 million?

## Exercise: Conditions in R

We have touched on many of these before, but here are some examples of expressions (conditions) in R.

```
pi > 3 & pi < 3.5
c(1,3,5,7) %in% 1:3
1:3 %in% c(1,3,5,7)
rand.uniform <- runif(n = 1, min = 0, max = 1)
rand.uniform < .5
```

## Exercise: Conditional Expression

Write a conditional statement that takes a playing card with two arguments:

- (
`card.number <- '4'`

and `card.suit <- 'C'`

= 4 of clubs or `card.number <-'K'`

and `card.suit <- 'H'`

= King of hearts) and
- Print
`Yes`

if the card is a red face card and `No`

otherwise.

Verify this works using the following inputs:

`card.number <- 'J'`

and `card.suit <- 'D'`

`card.number <- 'Q'`

and `card.suit <- 'S'`

## Exercise: Loops

Assume you plan to wager $1 on red for ten roulette spins. If the outcome is red you win a dollar and otherwise you lose a dollar. Write a loop that simulates ten rolls and determines your net profit or loss.

```
RouletteSpin <- function(num.spins){
# function to simulate roulette spins
# ARGS: number of spins
# RETURNS: result of each spin
outcomes <- data.frame(number = c('00','0',
as.character(1:36)),
color=c('green','green',
rep(c('red','black'),18)))
return(outcomes[sample(38,num.spins,replace=T),])
}
#hint: to get color from a single spin use
RouletteSpin(1)[2]
```

```
## color
## 14 black
```