pizza3_fb.py

Created by schraf

Created on January 05, 2022

1.47 KB

(L) contente 1er service
[0.2132 ; 0.2195]
(A) content 1er service
[0.4265 ; 0.4328]
(A) content si (L) contente
[0.4629 ; 0.4692]
(A) pleure si (L) pleure
[0.5781 ; 0.5844]


from random import *
from math import sqrt

# 4 parts poivrons et 4 parts chorizo
PIZZAS = list('PPPPCCCC')

# le cuisinier amene 2 parts
def deux(parts):
  # choix d'1 part
  p = choice(parts)
  # on l'enleve de l'ensemble des parts
  parts.remove(p)
  # choix 2e part
  v = choice(parts)
  p += v
  # on l'enleve
  parts.remove(v)
  # p est de la forme "PC", "CC" etc.
  return p

def simul(etat1, etat2, nbSimul = 100000):
  # nb de succes
  succes = 0
  n = 0
  # on fait nbSimul simulations
  while n < nbSimul:  
    parts = list(PIZZAS)
    # 1ere personne servie
    p1 = deux(parts)
    # si pas de 2e personne
    if etat2 == None:
      n += 1
      # si succes ajouter +1
      if p1 in etat1: succes += 1 
    # il y a 2e personne et succes pour p1
    elif p1 in etat1:
      n += 1
      # 2e personne servie
      p2 = deux(parts)
      # si succes pour p2 (et donc p1), ajouter +1
      if p2 in etat2: succes += 1
  p = succes / nbSimul
  err = 1 / sqrt(nbSimul)
  print(p - err, p + err) 

# (L)ouise contente si 2 parts poivrons
print('(L) contente 1er service')
simul(['PP'], None)
# (A)rthur content si 2 parts identiques
print('(A) content 1er service')
simul(['PP','CC'],None)
# On sait (L) contente (PP)
# (A) sera content si PP ou CC
print('(A) content si (L) contente')
simul(['PP'],['PP','CC'])
# On sait (L) pas contente
# elle a donc eu au moins 1 C
# (A) pleurera si parts differentes
print('(A) pleure si (L) pleure')
simul(['PC','CP','CC'],['CP','PC'])

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 cookies policy.