所以,我一直在研究 John Zelle 的 Python Programming 中的一个问题。问题是设计一个基本的二十一点程序,该程序演示二十一点经销商在给定规则他必须击中直到他大于 17 的情况下将失败的时间百分比。该程序旨在显示每张初始牌的可能性百分比,因为庄家经常亮出他的第一张牌。
我遇到的问题是,当我将它们与二十一点表交叉引用时,该程序似乎为除了 A 和十之外的每个值都提供了很好的百分比。
from random import randrange
def main():
printIntro()
n = getInput()
busts = simBlackjack(n)
printSummary(n, busts)
def printIntro():
print "Hello, and welcome to Blackjack.py."
print "This program simulates the likelihood"
print "for a dealer to bust."
def getInput():
n = input("How many games do you wish to simulate: ")
return n
def simBlackjack(n):
busts = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for b in range(10):
for i in range(n):
x = b + 1
if b == 0:
handAce = True
else: handAce = False
while x < 17:
add = randrange(1,14)
if add == 11:
add = 10
elif add == 12:
add = 10
elif add == 13:
add = 10
elif add == 1:
handAce = True
x = x + add
if handAce:
if x + 10 >= 17 and x + 10 <= 21:
x = x + 10
if x > 21:
busts[b] = busts[b] + 1
return busts
def printSummary(n, busts):
for b in range(10):
if b == 0:
print "When the initial card was Ace, the dealer busted %d times in %d games. (%0.1f%%)" % (busts[0], n, (busts[0]) / float(n) * 100)
else:
print "When the initial value was %d, the dealer busted %d times in %d games. (%0.1f%%)" % ((b + 1), busts[b], n, (busts[b]) / float(n) * 100)
if __name__ == "__main__": main()
如果 n = 1,000,000,我分别得到 ~ 11.5% 和 21.2%,这与在线表格保持的 17% 和 23% 显着不同。谁能让我知道问题是什么?