montyhall.py

Created by schraf

Created on May 25, 2023

593 Bytes

Le problème de Monty Hall ou les probabilités changent de porte | Voyages au pays des maths | ARTE

Visitez ma chaine YouTube


from random import *

rester, changer = 0, 0
nb_simul = 10000

for _ in range(nb_simul):
 portes = {1, 2, 3}
 cadillac = choice(list(portes))
 choix_1 = choice(list(portes))
 portes.remove(choix_1)
 if choix_1 != cadillac: portes.remove(cadillac)
 chevre = choice(list(portes))
 portes = {1, 2, 3}
 portes.remove(choix_1)
 portes.remove(chevre)
 choix_2 = choice(list(portes))
 if choix_1 == cadillac: rester +=1
 if choix_2 == cadillac: changer +=1
print('Proba en restant : {:3f}'.format(rester / nb_simul))    
print('Proba en changeant : {:3f}'.format(changer / nb_simul))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.