Python 文件操作、异常处理及相关应用详解
1. 扑克牌手牌计数功能函数
我们先来看用于计算扑克牌手牌概率的 compute 函数,代码如下:
def compute(file str):
while True:
try:
poker file = open(file str,'r')
break
except IOError:
print("Error opening file:",file str)
file str = input("Enter a file name: ")
total count = 0
nothing count = 0
pair count = 0
two pair count = 0
three of a kind count = 0
straight count = 0
flush count = 0
full house count = 0
four of a kind count = 0
straight flush count = 0
royal flush count = 0
for line str in poker file:
total count = total count + 1
fields = line str.split(',')
hand rank str = field
超级会员免费看
订阅专栏 解锁全文
2058

被折叠的 条评论
为什么被折叠?



