我创建一个列表:
temp_cards = []
然后将值添加到列表中:
for number in cards:
for type in suits:
temp_cards.append(str(number) + " of " + str(type))
然后我从列表中选择一个随机值并尝试获取索引 - 但它说它不在列表中。
dealers_card = random.choice(temp_cards)
y = cards.index(dealers_card)
print(y)
# ValueError: 'Two of Clubs' is not in list
但是我检查了它是否在列表中,它说是真的
x = dealers_card in temp_cards
print(x)
# True
temp_cards
由一系列格式为"花色数量"的字符串组成。该字符串不在cards
中,它由一系列数字组成。