samedi 24 août 2019

How to remove certain int from list within a list?

I'm trying to make a blackjack game as a beginners project. When I try to remove the card that's being dealt from the deck I get this: ValueError: list.remove(x): x not in the list. How can I fix this?

This is my code:

import random

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

def deal_cards():
    number = random.choice(deck[0:][0:]) # selecting the number of the card
    card = random.choice(number) # selecting wich suit from the number sould be the card
    new_deck = deck.remove(card) # Here is the problem
    print(new_deck)
    print(card)

deal_cards()




Aucun commentaire:

Enregistrer un commentaire