import random
# 在打完牌后移除该卡片
def remove_card(str_card_list, card_list):
for i in str_card_list:
card_list.remove(i)
# 出1张牌
def one_card(card_list):
return [random.choice(card_list)]
# 出2张牌
def two_card(card_list):
card_set = set(card_list)
for card in card_set:
count = card_list.count(card)
if count >= 2:
return [card, card]
# 出5张牌
def five_card(card_list):
test_list = [
["2", "3", "4", "5", "6"],
["3", "4", "5", "6", "7"],
["4", "5", "6", "7", "8"],
["5", "6", "7", "8", "9"],
["6", "7", "8", "9", "10"],
["7", "8", "9", "10", "J"],
["8", "9", "10", "J", "Q"],
["9", "10", "J", "Q", "K"],
["10", "J", "Q", "K", "A"],
]
for i in test_list:
if set(i).issubset(set(card_list)):
return i
# 示例卡牌号码:2 3 4 5 7 8 9 10 J J Q K A
card_list = input("请输入卡牌号码:").split()
# 先一直出5张牌
num = 0
while True:
try:
five_card_list = five_card(card_list)
remove_card(five_card_list, card_list)
num += 1
except TypeError:
break
# 然后出2张牌
while True:
try:
two_card_list = two_card(card_list)
remove_card(two_card_list, card_list)
num += 1
except TypeError:
break
# 最后随机出1张牌
for i in card_list:
num += 1
print(num)
标签:10,set,短时间,完牌,list,张牌,num,内出,card
From: https://www.cnblogs.com/tiansz/p/17047303.html