1. Generate a deck of playing cards (design the structure of the playing cards by yourself, Xiao Wang and King can be represented by 14 and 15 respectively)
2. 3 players (players can also define by themselves)
3. The card dealing rules
default to deal a card to the user first, among which the values represented by J, Q, K, Xiao Wang and King are 0.5, and the others are the current cards face value.
The user judges whether to continue to ask for cards according to his own situation.
If so, send him another one. (You can always ask for cards, but if the sum of the cards in your hand exceeds 11 points, your cards will be blown (the card face becomes 0))
If you don’t want to, start to deal cards to the next player. (If there is no card, the default value of the card is 0.)
If the sum of all the cards in the user's hand is greater than 11, it means that the player is busted, and the person's score is 0, and the card will be automatically dealt to the next person.
4. Finally calculate and get the score of each player
必备技术点:随机抽排
import random
total_poke_list = [("红桃", 1), ("黑桃", 2), ......,("大王", 15), ("小王", 14)]
# 随机生成一个数,当做索引。
index = random.randint(0, len(total_poke_list) - 1)
# 获取牌
print("抽到的牌为:", total_poke_list[index])
# 踢除这张牌
total_poke_list.pop(index)
print("抽完之后,剩下的牌为:", total_poke_list)
# 全套扑克牌
# 全套扑克牌
color_list = ["红桃", "黑桃", "方片", "梅花"]
color_list = ["红桃", "黑桃", "方片", "梅花"]
num_list = []
for num in range(1, 14):
num_list.append(num)
total_poke_list = []
for color in color_list:
for num in num_list:
text = color,num
total_poke_list.append(text)
total_poke_list.append(("小王",14))
total_poke_list.append(("大王",15))
print(total_poke_list)
# 按照顺序抽牌
# for name in user_list:
# print(name)
# y = True
# while y:
# choose = input("是否要牌:")
# import random
# index = random.randint(0, len(total_poke_list) - 1)
# total = total_poke_list[index] #抽到的卡牌为total
# print("抽到的牌为:", total_poke_list[index])
# total_poke_list.pop(index)
# print("抽完之后,剩下的牌为:", total_poke_list)
# if choose == "n":
# print("此轮抽牌结束")
# break
user_list = ["张三","李四","王五"]
result = {
"张三":0,
"李四":0,
"王五":0
}
# total_poke_list = [("红桃", 1), ("黑桃", 2), ......,"大王”,“小王”]
import random
for name in user_list:
print(name)
index = random.randint(0, len(total_poke_list) - 1)
total = total_poke_list[index] # 抽到的卡牌为total
num = int(total[1])
print("抽到的牌为:", total_poke_list[index])
total_poke_list.pop(index)
print("抽完之后,剩下的牌为:", total_poke_list)
# num1为当前的点数
if num < 11:
num1 = int(num)
else:
num1 = 0.5
print("此张牌的点数为:")
print(num1)
scorse1 = num1
scorse = 0 + scorse1
while True:
choose = input("是否继续要牌:")
if choose == "n":
print("此轮抽牌结束")
print(input("按任意键查看当前点数情况"))
result[name] = scorse
print(result)
break
if choose != "n":
index = random.randint(0, len(total_poke_list) - 1)
total = total_poke_list[index] # 抽到的卡牌为total.
print("抽到的牌为:", total_poke_list[index])
total_poke_list.pop(index)
print("抽完之后,剩下的牌为:", total_poke_list)
num = int(total[1])
if num < 11:
num1 = int(num)
else:
num1 = 0.5
scorse = scorse + num1
print("此张牌的点数为:")
print(num1)
print("当前点数共:")
print(scorse)
if scorse > 11:
scorse = 0
print("总点数超过11,当前点数为0")
print(scorse)
break
result[name] = scorse
print(result)