dimanche 10 novembre 2019

Creating a function that returns a list of 5 cards drawn from a shuffled deck without replacement

I am creating a function that returns a list of 5 cards drawn from a shuffled deck without replacement. I have to run function 10000 times and calculate the number of times where the 5 cards contain 4 of the same kind, for example: ['2 of Spades', '3 of Clubs', '2 of Diamonds', '2 of Spades', '2 of Hearts']. Below is the code I Have so far

import random


suits = ['Spades','Clubs','Hearts','Diamonds']
cards = list('23456789JQKA')
cards.insert(8,'10')
deck = [card+' of '+suit for card in cards for suit in suits]


def draw_wo_replacement(deck):
    for i in range (5):
        newdeck=[]
        index = random.randint(0,len(deck)-1)
        card = deck[index]
        deck.pop(index)
        newdeck.append(card)
    return newdeck
print(draw_wo_replacement(deck))

the new deck I am trying to print only comes out with one value, not sure why the loop is not working. and I am unsure of how I could run this 10000 or how to calculate the number of times where the 5 cards contain 4 of the same kind




Aucun commentaire:

Enregistrer un commentaire