私信  •  关注

DarkLeader

DarkLeader 最近创建的主题
DarkLeader 最近回复了
6 年前
回复了 DarkLeader 创建的主题 » python 21点:如何构造if语句以确定是否应将ace转换为1?
def blackjack(a,b,c):

    Ace_count = [a,b,c].count(11)

    total = sum([a,b,c])

    if total <= 21:
        return ("Not busted", total)

    while total > 21:
        if Ace_count > 0:
            Ace_count -= 1
            total -= 10
        else:
            return "Bust"

    return ("Not busted", total)

print(blackjack(11,11,11))

我认为这应该有效,返回:

('Not busted', 13)