Python 3.x 循环使用Python中的系统参数
这是一个21点程序。当stand函数为false时,主函数不应该将getCard()附加到myCards中,但出于某种原因,它仍然会附加getCard(),并且会向后计数。我不知道我做错了什么Python 3.x 循环使用Python中的系统参数,python-3.x,function,for-loop,while-loop,Python 3.x,Function,For Loop,While Loop,这是一个21点程序。当stand函数为false时,主函数不应该将getCard()附加到myCards中,但出于某种原因,它仍然会附加getCard(),并且会向后计数。我不知道我做错了什么 import random import sys def get_card(): return random.randint(1, 13) def score(cards): soft_ace_count = 0 total = 0 Ace = False 检查手上是否有Ace,并将人脸卡设置为正确
import random
import sys
def get_card():
return random.randint(1, 13)
def score(cards):
soft_ace_count = 0
total = 0
Ace = False
检查手上是否有Ace,并将人脸卡设置为正确的值
转换Ace
对于卡中的x:
如果Ace和total>21:
总数-=10
软磁盘计数-=1
返回(总、软磁盘计数)
def支架(支架上的支架、支架上的支架、软卡):
总数,软卡数量=得分(卡)
打印(f“支架内:{total}”)
如果总数大于17且总数小于22:
返回真值
如果总计==支持值:
返回真值
elif软磁盘计数=0,总计数=17:
返回真值
elif stand_on_soft==真,总计==17:
返回真值
其他:
返回错误
def编号:
总软磁盘计数=s
损坏的计数=0
如果总数>21:
损坏的_计数+=1
返回损坏的计数
def main():
numSims=int(sys.argv[1])-1
standVal=int(sys.argv[2])
策略=sys.argv[3]
策略.上()
对于范围内的SIM(numSims+1):
百分比=0.0
myCards=[get_card(),get_card()]
打印(f“主:前两张卡:{myCards}”)
展位(展位、策略、我的名片)
而不是站着(站着,策略,我的卡):
myCards.append(get_card())
胸围百分比=(numBusts(分数(myCards))/(numSims+1))*100
打印(f“主:胸围百分比:{胸围百分比}”)
如果名称=“\uuuuu main\uuuuuuuu”:
[此图显示了它如何正确运行,直到while not stand函数返回False。][1]main()
我试过运行循环,而不是运行循环,以及其他事情
请提供帮助。
而非stand
将在stand为False时将get_card()的结果附加到myCards
但是在你的问题中,你说当stand()为False时,你不希望它附加
另外,您似乎连续两次调用stand函数,这是有意的吗?条件函数实际上调用函数以检查其结果
也许这会满足你的期望
for sims in range(numSims+1):
percent_bust = 0.0
myCards = [get_card(), get_card()]
print(f"in main: first two cards: {myCards}")
if stand(standVal, strategy, myCards) is True:
myCards.append(get_card())
当且仅当
stand()
返回True时,此条件才会附加到myCards;当stand()返回False、0或None时,此条件才会附加到myCards。当stand为False时,此条件才会附加到get_card()的结果到myCards
但是在你的问题中,你说当stand()为False时,你不希望它附加
另外,您似乎连续两次调用stand函数,这是有意的吗?条件函数实际上调用函数以检查其结果
也许这会满足你的期望
for sims in range(numSims+1):
percent_bust = 0.0
myCards = [get_card(), get_card()]
print(f"in main: first two cards: {myCards}")
if stand(standVal, strategy, myCards) is True:
myCards.append(get_card())
当且仅当stand()
返回True,而返回False、0或None时,此条件将附加到myCards
for sims in range(numSims+1):
percent_bust = 0.0
myCards = [get_card(), get_card()]
print(f"in main: first two cards: {myCards}")
if stand(standVal, strategy, myCards) is True:
myCards.append(get_card())