開始使用免費開始

在「更換選門」下的獲勝機率

現在來撰寫程式:參賽者一開始選擇第 1 號門,主持人揭示一扇有山羊的門後,參賽者改選剩下的那扇門。

同樣地,先只寫單次模擬。接著把它放進 for 迴圈重複執行,以取得對真實獲勝機率的模擬估計。

本練習屬於課程

R 的機率謎題

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

set.seed(1)
prize <- sample(doors,1)
initial_choice <- 1

# Use the reveal_door function to do the reveal
reveal <- reveal_door(___, ___, ___)

# Switch to the remaining door
final_choice <- ___
print(final_choice)

# Check whether the final choice equals the prize
if(___){
  print("The final choice is correct!")
}
編輯並執行程式碼