检查项目是否在列表中说它是真的,然后不会让我引用索引,因为它说该项目不在列表中



我创建一个列表:

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中,它由一系列数字组成。

最新更新