Simulates the Mounty Hall problem. n is the number of simulations, change is True if the player changes and False if he keeps his first choice.
from random import randint,choice def mh(n,change): gagne=0 for _ in range(n): voiture=randint(0,2) joueur=randint(0,2) porte=choice([i for i in range(3) if i not in [voiture,joueur]]) if change: joueur=choice([i for i in range(3) if i not in [joueur,porte]]) if joueur==voiture: gagne+=1 print("gains %f"%(gagne/n))