我对下面代码中的my last elif和else语句有一个相当简单的问题。。。他们根本不会执行。我是python的高手,所以很可能是个简单的错误:/ 控制台不显示任何语法错误或任何。。。它执行代码,但结果错误
starthandvalue = 0
if splitfirstcard[0] == splitsecondcard[0]:
ispar = True
if (splitfirstcard[0] and splitsecondcard[0] == 'A') or (splitfirstcard[0] and splitsecondcard[0]== 'K') or (splitfirstcard[0] and splitsecondcard[0] == 'Q'):
starthandvalue =+83
elif (splitfirstcard[0] and splitsecondcard[0] == 'J') or (splitfirstcard[0] and splitsecondcard[0] == '10') or (splitfirstcard[0] and splitsecondcard[0] == '9'):
starthandvalue =+75
elif (splitfirstcard[0] and splitsecondcard[0] == '8') or (splitfirstcard[0] and splitsecondcard[0] == '7') or (splitfirstcard[0] and splitsecondcard[0] == '6') or (splitfirstcard[0] and splitsecondcard[0] == '5'):
starthandvalue ==+62
else:
starthandvalue ==+55
输出
['Q', 's'] ['Q', 'h']
Hand value: about 83%
['9', 's'] ['9', 'h']
Hand value: about 75%
['6', 's'] ['6', 'h']
Hand value: about 0% <--- this should be 62
['2', 's'] ['2', 'h']
Hand value: about 0% <--- this should be 55
['3', 's'] ['3', 'd']
Hand value: about 0% <--- this should be 55
['K', 's'] ['K', 'd']
Hand value: about 83%
```
快速一瞥,
splitfirstcard[0] and splitsecondcard[0] == '5'
并不是你想的那样。这些语句应该是splitfirstcard[0] == 5 and splitsecondcard[0] == '5'
例如:
将诸如
=+
和==+
之类的运算符更改为+=
相关问题 更多 >
编程相关推荐