cartes.py

Created by ph-moutou

Created on April 21, 2018

890 Bytes

Ce programme distribue n cartes d’un paquet de 32 (fonction cartes1(n)) ou bien n cartes à p joueurs (fonction cartes2(n,p)).


from random import *
def cartes1(n):
    coul=['Trefle','Carreau','Coeur','Pique']
    vale=['7','8','9','10','Valet','Dame','Roi','As']
    main=[]
    while len(main)<n:
        carte="{} de {}".format(choice(vale),choice(coul))
        if carte not in main : main.append(carte)
    return main

def cartes2(n,p):
    coul=['Trefle','Carreau','Coeur','Pique']
    vale=['7','8','9','10','Valet','Dame','Roi','As']
    jeu,mains=[],[]
    for c in coul:
        for v in vale:
           jeu.append("{} de {}".format(v,c))
    for i in range(p):
        main=[]
        while len(main)<n:
            main.append(jeu.pop(randrange(len(jeu))))
        mains.append(main)
    return mains

nb_cartes,nb_joueurs=8,4
jeux=cartes2(nb_cartes,nb_joueurs)
for i in range(nb_joueurs):
    print("Joueur {}:".format(i+1))
    print(" - ".join(jeux[i]))

#print(" - ".join(cartes1(4)))v

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.