Python的扑克牌十一点写法
#11点
#生成扑克牌
poke_color = ['红桃','黑桃','方块','梅花']
poke_list = [('大王',0.5),('小王',0.5)]
for i in poke_color:
for j in range(1,14):
poke_list.append((f'{i}{j}',j))
print(poke_list)
#循环每个用户进行分数计算
poke_play_user = ['alex','武沛齐','李路飞']
#每个用户单独循环一次,再询问
import random
result = {}
for i in poke_play_user:
#基础抽卡
#获取收到的数据
score = 0
random_index = random.randint(0,len(poke_list)-1)
data = poke_list.pop(random_index) #('红桃4', 4)
#分数判断并相加
value = data[1]
if value > 10:
value = 0.5
score += value
print(f'{i}抽到了{data[0]},总分数为{score}')
#附加抽卡
while True:
#判断输入合法
user_poke_input = input(f'{i}是否需要抽卡:y/N').strip().upper()
if user_poke_input not in ['Y','N']:
print('输入错误')
continue
if user_poke_input == 'N':
print(f'{i}抽卡结束')
break
#抽卡
random_index = random.randint(0, len(poke_list) - 1)
data = poke_list.pop(random_index) # ('红桃4', 4)
#判断分数
value = data[1]
if value > 10:
value = 0.5
score += value
print(f'{i}抽中了{data[0]},得分{value}现在总分为{score}')
#查看是否符合结束游戏
if score>11:
print(f'{i}爆了,得分{score}')
score = 0
break
result[i] = score
print(result)