In [1]:
import random
In [8]:
random.seed(12345678)
for i in range(10):
print(random.randint(1,6))
In [9]:
casos_totales = 0
casos_favorables = 0
while casos_favorables < 10000:
veces = [0,0,0,0,0,0,0]
for i in range(4):
veces[random.randint(1,6)] += 1
son_distintos = True
for i in range(7):
if veces[i] > 1:
son_distintos = False
casos_totales += 1
if son_distintos == True:
casos_favorables += 1
print("Probabilidad = ", casos_favorables/casos_totales)
In [10]:
veces
Out[10]:
In [11]:
mi_carton = [2, 4, 25, 29, 37, 38]
In [14]:
gane = False
experimentos = 0
veces = [0,0,0,0,0,0,0]
while gane == False:
experimentos += 1
sorteados = []
for i in range(7):
candidato = random.randint(1,41)
while candidato in sorteados:
candidato = random.randint(1,41)
sorteados.append(candidato)
puntos = 0
for i in mi_carton:
for j in sorteados:
if i == j:
puntos += 1
veces[puntos] += 1
if puntos == 6:
gane = True
print(experimentos)
In [15]:
print(veces)
In [16]:
print("Proba de sacar 0 puntos =", 35*34*33*32*31*30*29/41/40/39/38/37/36/35)
In [17]:
veces[0]/experimentos
Out[17]:
In [18]:
print("Proba de sacar 1 punto =", 7*6*35*34*33*32*31*30/41/40/39/38/37/36/35)
In [19]:
print(veces[1]/experimentos)
In [20]:
print("Proba de sacar 2 puntos =", 21*6*5*35*34*33*32*31/41/40/39/38/37/36/35)
In [21]:
print(veces[2]/experimentos)