Skip to content

Instantly share code, notes, and snippets.

@jeanpat
Last active September 5, 2022 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeanpat/281b030f3e33d23040693809fc5d9bcc to your computer and use it in GitHub Desktop.
Save jeanpat/281b030f3e33d23040693809fc5d9bcc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 17 17:56:29 2019
Simulation du jeux MONTY HALL
@author: jean-patrick Pommier
"""
# random : module permettant de faire des tirages aléatoire
import time
import random
print(time.strftime(' %d /%m/%Y %H:%M:%S'))
gain = 0
#Nombre de répétitions du jeux
N_JEUX = 100
print("Un joueur joue ",N_JEUX," fois au jeu de Monthy Hall:")
print('le joueur ne change pas son choix')
for jeux in range(N_JEUX):
#liste contenant le numéro de chacub=ne des trois portes
PORTES = [1, 2, 3]
# On choisit une des trois portes
voiture = random.choice(PORTES)
choix1_joueur = random.choice(PORTES)
# Le présentateur choisit une porte au hasard sauf celle
# qui cache la voiture
PORTES.remove(voiture)
if voiture != choix1_joueur:
PORTES.remove(choix1_joueur)
presentateur = random.choice(PORTES)
if choix1_joueur == voiture:
gain = gain + 1
print(' le joueur gagne :', gain,' fois sur ',N_JEUX)
print('le joueur change son choix')
gain = 0
for jeux in range(N_JEUX):
PORTES = [1, 2, 3]
voiture = random.choice(PORTES)
choix1_joueur = random.choice(PORTES)
#le présentateur ne choisit pas la porte de la voiture
PORTES.remove(voiture)
if voiture != choix1_joueur:
PORTES.remove(choix1_joueur)
presentateur = random.choice(PORTES)
#Le joueur change d'avis
#On a besoin de la liste des trois portes
PORTES = [1, 2, 3]
#le joueur ne choisit pas la porte ouverte(donc on supprime la porte du presentateur)
PORTES.remove(presentateur)
#le joueur ne choisit pas son premier choix(donc on supprime la porte du premier choix)
PORTES.remove(choix1_joueur)
#astuce pour avoir le numéro de la porte et pas une liste
choix2_joueur = PORTES.pop()
if choix2_joueur == voiture:
gain = gain + 1
print(' En changeant son choix, le joueur gagne :', gain,' fois sur ',N_JEUX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment