1
我试图找出如何找到下一张牌的概率。我不知道如何检查下一张牌并获得概率,也不知道该怎么办,将它们一起写入每种牌的单独方法中。任何帮助我能够读到一张牌的手,并找到获得这手牌的可能性将不胜感激。Python输入文件中的扑克概率
编写一个读取文本文件的程序。该名称将作为命令行参数提供给 。每一行都会给你一份你目前掌握的 中4张卡片的列表。在该文件中读取后,你的程序将打印 出每种类型的胜负手,其中一个胜负手 给出的概率
import sys
#error message
if len (sys.argv) == 1:
print "Error"
exit()
file = sys.argv[1]
#counts and arrays
#count = 0
f = open(file)
f = f.read()
hand = f.splitlines()
arraynum = 0
def deck():
deck = []
suit = ['H', 'S', 'D', 'C']
number = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
for s in suit:
for n in number:
deck.append(n+s)
return deck
def startHand(arraynum):
hand1 = str(hand[arraynum]).split(', ')
hand1.sort()
return hand1
def checkHand(deck,hand1):
for card in hand1:
for Card in deck:
if Card == card:
deck.remove(card)
return deck
def check1(deck, hand1):
count = 0
for Card in deck:
for i in hand1[0:-1]:
if i != Card:
count +=1
prob = count/48
print prob
print count
t1 = deck()
t2 = startHand(3)
t3 = checkHand(t1,t2)
t4 = check1(t2,t3)'
输入文件是: QS,JS,KS,10S KS,3C,3S,QC 6D,10D,AD,7D
输出应该是这样的:
('Chance of Royal Flush: ', 0.020833333333333332)
('Chance of Straight Flush: ', 0.020833333333333332)
('Chance of Four of a Kind: ', 0.0)
('Chance of Full House: ', 0.0)
('Chance of Flush: ', 0.14583333333333334)
('Chance of Straight: ', 0.125)
('Chance of Three of a Kind: ', 0.0)
('Chance of Two Pair: ', 0.0)
('Chance of Pair: ', 0.25)
('Chance of High Card: ', 0.4375)
*************************************
('Chance of Royal Flush: ', 0.0)
('Chance of Straight Flush: ', 0.0)
('Chance of Four of a Kind: ', 0.0)
('Chance of Full House: ', 0.0)
('Chance of Flush: ', 0.0)
('Chance of Straight: ', 0.0)
('Chance of Three of a Kind: ', 0.041666666666666664)
('Chance of Two Pair: ', 0.125)
('Chance of Pair: ', 0.8333333333333334)
('Chance of High Card: ', 0.0)
*************************************
('Chance of Royal Flush: ', 0.0)
('Chance of Straight Flush: ', 0.0)
('Chance of Four of a Kind: ', 0.0)
('Chance of Full House: ', 0.0)
('Chance of Flush: ', 0.1875)
('Chance of Straight: ', 0.0)
('Chance of Three of a Kind: ', 0.0)
('Chance of Two Pair: ', 0.0)
('Chance of Pair: ', 0.25)
('Chance of High Card: ', 0.5625)
*************************************
欢迎来到StackOverflow。请阅读并遵守帮助文档中的发布准则。 [在主题](http://stackoverflow.com/help/on-topic)和[如何提问](http://stackoverflow.com/help/how-to-ask)适用于此处。 StackOverflow不是一个编码或教程服务。 – Prune