शुरू करेंमुफ़्त में शुरू करें

Function to run one round

Now, let us use the function from the previous exercise, and write one overall function, called evaluate_first_roll, to complete one round of Craps. As seen in the sample code below, this function will take the shooter's first roll as its input, and proceed accordingly from there. The roll_dice and roll_after_point functions have been preloaded for you.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Probability Puzzles in R

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Use the %in% operator to check whether the roll is a 7 or 11, resulting in an immediate win.
  • Use the %in% operator to check whether the roll is a 2, 3, or 12, resulting in an immediate loss.
  • If a point is established, continue rolling until either the point is rolled again, resulting in a win, or a 7 is rolled, resulting in a loss.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

evaluate_first_roll <- function(roll){
  # Check whether the first roll gives an immediate win
  if(___){
    won <- TRUE
  }
  # Check whether the first roll gives an immediate loss
  if(___){
    won <- FALSE
  }
  if(roll %in% c(4,5,6,8,9,10) ){
    # Roll until the point or a 7 is rolled and store the win/lose outcome
    won <- ___
  }  
  return(won)
}
कोड संपादित करें और चलाएँ