ComeçarComece de graça

Function to keep rolling when point is established

Let us code the function that will handle all rolling that occurs after a point has been established. Recall that this means it should continue rolling until either the point is rolled again, or a 7 is rolled. Once either of these happens, it should stop, and report back whether the result is a win or a loss.

Note that within this function, we will again use the roll_dice function that we previously defined.

Este exercício faz parte do curso

Probability Puzzles in R

Ver curso

Instruções do exercício

  • Fill in the conditions in the while loop to continue rolling until either a 7 or the point is rolled.
  • Fill in the condition to check if the most recent roll will result in a win.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

roll_after_point <- function(point){
  new_roll <- 0
  # Roll until either a 7 or the point is rolled 
  while( ___ ){
    new_roll <- roll_dice(2)
    if(new_roll == 7){
      won <- FALSE      
    }
    # Check whether the new roll gives a win
    if(___ == ___){
      won <- TRUE
    }
  }
  return(won)
}
Editar e executar o código