My program involves drawing a card from a deck, adding the value of it to my hand and then deleting the card from the deck (since I don't want to draw the same card twice).
Example of a card:
card = ["4 of clubs", 4]
The code that doesn't work:
card_number = random.randrange(len(deck_cards))
card = deck_cards[card_number][0]
print(card)
hand_value += deck_cards[card_number][1]
deck_cards.remove(card_number)
I have no idea what I am doing wrong, and if I change the code to
card_number = random.chioce(deck_cards)
it won't accept the card = deck_cards[card_number][0] part.
What to do?
deck_cards.remove(card_number)should bedeck_cards.remove(deck_cards[card_number])The parameter is the element to remove, not its index. Try typinghelp(list.remove)in the REPL. It will tell you,L.remove(value) -> None -- remove first occurrence of value.