Open gzbib opened 4 years ago
Congratulations, you are the first one to catch this bug :-)
Your code currently is FINE to receive credit for the lab. The logic is intact, and the function is structured properly.
I'm not going to tell you the issue just yet, but it is a case of a function not operating as expected when you encounter certain edge cases. I will explain more after labs have been submitted.
Feel free to keep looking to see if you can identify the source of the error (it is very subtle).
But no problem if you can't see it. This is a bug I leave in the lab to emphasize the importance of these unit tests. Most students don't catch it. I'll explain the problem and the fix in the solutions file.
Hi Professor Lecy, I am working through how to fix the bug for step 3. I noticed it looks like you may have to identify the parts of the function (they were left in the code without the <- part). I tried a couple of different options, but am a bit stuck.
Below is the code I am using as well as the error. Do you have any hints?
Error in sample.int(length(x), size, replace, prob) : invalid first argument
open_goat_door <- function(game, a.pick)
{
game <- c("goat","goat","car")
a.pick <- c(1,2,3)
doors <- c(1,2,3)
possible.doors <- doors[game == "goat" & doors != a.pick]
opened.door <- sample(possible.doors,
size = 1)
return(opened.door) # number between 1 and 3
}
Hello Sir @lecy
I am confused regarding step03, after several randomizations, I am getting the same number for the initial pick and the open_goat_door () . Kindly check the below code and a sample answer:
open_goat_door <- function( game, a.pick)