简体   繁体   English

条件语句似乎无法获取Python中变量的值

[英]Conditional Statement seems to not get the value of a variable in Python

 else:
    for i in hand1.cardList:
        if i.value==1: # if there is an ace in the hand

            print "Soft Sum: %d "% hand1.soft_sum()
            if hand1.soft_sum()==21:
                outcome="player_black_jack"             

        print out_come

This code checks to see if there is a card of value 1 in hand1.cardList . 此代码检查一下hand1.cardList是否存在值为1的卡。 If there is a card of value 1 then the code gets a soft sum value from hand1.soft_sum() . 如果有一张值为1的卡,则代码从hand1.soft_sum()获得一个软和值。 The code then prints out the correct value of the class method hand1.soft_sum() . 然后,代码打印出类方法hand1.soft_sum()的正确值。 The code then tests to see if the hand1.soft_sum() is equal to 21 ...if it is equal to to 21 then the code should set out_come to "black_jack". 然后,代码进行测试以查看hand1.soft_sum()是否等于21 ...如果等于21则代码应将out_come设置为“ black_jack”。 I have ran this code and even when the hand1.soft_sum() IS equal to 21 I get this: 我已经运行了这段代码,即使hand1.soft_sum()等于21时,我也得到了:

***HAND 1***  
♣ K ♠ A 
Hard Sum: 11  
Soft Sum: 21

It is supposed to then print "player_black_jack" But it does not. 然后应该打印“ player_black_jack”,但不会。

try converting it to int manually like so: 尝试将其手动转换为int,如下所示:

 else:
    for i in hand1.cardList:
        if i.value==1: # if there is an ace in the hand

            print "Soft Sum: %d "% hand1.soft_sum()
            if int(hand1.soft_sum())==21:
                out_come="player_black_jack"             

        print out_come

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM