All problems
Monty Hall Switch Win Probability
Problem
In the Monty Hall game you pick one of n_doors doors, the host opens a different door with no prize, and you switch to one of the remaining n - 2 unopened doors. Return the probability that switching wins:
P = (n - 1) / (n * (n - 2)).
Return 0.0 when n_doors < 3, since there is nothing to switch to.
Hint
Your first pick wins with probability 1 / n, and the prize is behind all other unopened doors otherwise.
Test cases
case 1
in: [3]
expected: 0.6666666666666666
case 2
in: [4]
expected: 0.375
case 3
in: [5]
expected: 0.26666666666666666
case 4
in: [2]
expected: 0
Starter codePython
def monty_hall_switch_win(n_doors):
# Your code here
pass4 test cases · run your code against them in the editor