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)

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.