lundi 30 mai 2022

Why is sum of random.choice returning the same total when ran multiple times in Python? [closed]

I'm experimenting with a 'deck of cards', but when I try to randomly call a number from the deck, the sum is always the same, as shown below. I can't figure out why this is happening. Shouldn't random.choice(list) call a random value from the deck?

deck = [
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4 , 5 , 6, 7, 8, 9,
    1, 2, 3, 4 , 5 , 6, 7, 8, 9,
    1, 2, 3, 4 , 5 , 6, 7, 8, 9,
    10, 10, 10, 10,
    10, 10, 10, 10,
    10, 10, 10, 10,
    10, 10, 10, 10
    ]

user_card_1 = random.choice(deck)
deck.remove(user_card_1)

dealer_card_1 = random.choice(deck)
deck.remove(dealer_card_1)

user_card_2 = random.choice(deck)
deck.remove(user_card_2)

dealer_card_2 = random.choice(deck)
deck.remove(dealer_card_2)

user_hand = user_card_1 + user_card_2
dealer_hand = dealer_card_1 + dealer_card_2

print(f"Your hand: {user_hand} ({user_card_1} and {user_card_2})")
print(f"Dealer's hand: {user_hand} ({dealer_card_1} and {dealer_card_2})")

Example output:

Your hand: 10 (4 and 6)
Dealer's hand: 10 (10 and 8)



Aucun commentaire:

Enregistrer un commentaire