【发布时间】:2019-12-29 11:02:57
【问题描述】:
我正在尝试将二十一点游戏作为初学者项目。当我尝试从牌组中取出正在处理的牌时,我得到这个: ValueError: list.remove(x): x not in the list。我该如何解决这个问题?
这是我的代码:
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()
【问题讨论】:
标签: python list function random blackjack