collectionneur.py

Created by ph-moutou

Created on June 05, 2018

510 Bytes

Ce programme effectue des tirages aléatoires parmi n objets jusqu’à obtenir la collection complète des objets. L’affichage donne la première et la dernière occurrence ainsi que le nombre d’objets de chaque sorte.


from random import randint
def collection(n):
    t=0 #nombre de tirages
    L1,L2,L3=n*[0],n*[0],n*[0]
    while L1.count(0)>0 :
        t+=1
        r=randint(0,n-1)
        if L1[r]==0:L1[r]=t
        L2[r]=t
        L3[r]+=1
    print("{} objets obtenus en {} tirages".format(n,t))
    affichage(L1,L2,L3)

def affichage(l1,l2,l3):
    print("|objet|first|last|nombre|")
    for i in range(len(l1)):
        print("|{:5}|{:5}|{:4}|{:6}|".format(i+1,l1[i],l2[i],l3[i]))

collection(9)