Krazy King二十一点【难度:3级】--景越Python编程训练之挑战1000道Python面试题(含答案)

Krazy King二十一点【难度:3级】:

Krazy King BlackJack就像二十一点,有一点不同:国王!
国王在比赛开始时宣布10分或其他数量的分数,而不是国王只值10分。无论哪个价值产生最好的牌都是最好的牌(很像是A值值1或11点)。

编写一个输入字符串列表(表示二十一点手)的函数和一个表示替代王值的整数。如果小于或等于21,该函数应输出表示手的值的整数,如果超过21,则输出False。除了替代的王值,正常的大酒杯规则适用。

这些牌按照ace-through king的顺序表示为字符串,如下所示:

['A','2','3','4','5','6','7','8','9','10','J','Q',' K']

一只手有2到20张牌,包括在内。替代王的价值在2到9之间,包括在内。

二十一点规则:一只手的价值是通过最大化其牌的总和来确定的,如果可能的话,不超过21。数字卡值得他们的价值,杰克(‘J’)和皇后(‘Q’)值10,Aces值1或11,而国王再值10或其替代价值。

英文原题:

Krazy King BlackJack is just like blackjack, with one difference: the kings!
Instead of the kings being simply worth 10 points, kings are worth either 10 points or some other number of points announced by the dealer at the start of the game. Whichever value yields the best hand is the one that plays (much like how aces are worth either 1 or 11 points).

Write a function that inputs a list of strings (representing a blackjack hand) and an integer that represents the alternative king value. The function should output an integer representing the value of the hand if it is less than or equal to 21, and False if it exceeds 21. Other than the alternative king value, normal blackjack rules apply.

The cards, in order ace-through king, are represented as strings as follows:

['A', '2', '3','4', '5', '6','7', '8', '9','10', 'J', 'Q','K']

A hand has between 2 and 20 cards, inclusive. The alternative king value is between 2 and 9, inclusive.

Blackjack rules: the value of a hand is determined by maximizing the value of the sum of its cards while not exceeding 21 if possible. Number cards are worth their value, Jacks (‘J’) and Queens (‘Q’) are worth 10, Aces are worth either 1 or 11, and kings, again, are worth either 10 or their alternative value.

最佳答案合集(多种解法):

点击查看答案

更多关联题目:

简单的乐趣#31:替换密码?【难度:2级】–景越Python编程训练之挑战1000道Python面试题(含答案)

免责申明:

本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值