python 11点小游戏

"""
需求:11点小游戏
人员超出11点默认为0
每次选完牌后询问是否继续
"""

import random

result = {}

user_list = ["yy", "ww", "gg"]

total_poke_list = [ ("小王",14),("大王",15) ]
color_list = ["红桃", "黑桃", "方片", "梅花"]
num_list = []
for num in range(1, 14):
    num_list.append(num)
for color in color_list:
    for num in num_list:
        item = (color, num,)
        total_poke_list.append(item)

for user in user_list:
    score = 0
    index = random.randint(0, len(total_poke_list) - 1)
    poke = total_poke_list.pop(index) 
    value = poke[1]
    if poke[1] > 10:
        value = 0.5 
    score += value
    print("给{}发的牌:{}{},此刻所有牌面值总和:{}".format(user, poke[0], poke[1], score))
    
    while True:
        choice = input("是否继续要牌(Y/N)?")
        choice = choice.upper()

        if choice not in {"Y", "N"}:
            print("输入错误,请重新输入。")
            continue

        if choice == "N":
            print("{}不要拍了".format(user))
            break

        index = random.randint(0, len(total_poke_list) - 1)
        poke = total_poke_list.pop(index)
        value = poke[1]
        if poke[1] > 10:
            value = 0.5
        score += value
        
        print("给{}发的牌:{}{},此刻所有牌面值总和:{}".format(user, poke[0], poke[1], score))

        if score > 11:
            print("用户{}爆了".format(user))
            score = 0
            break

    result[user] = score

print(result)
posted @   咖啡馆  阅读(96)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示