我正在开发一个python程序,它会分析用户输入的两张卡片。有(根据研究)你可以获得前两张牌的169种不同的可能性,没有特定的套装。例如,如果他们是同一套装,那么ace和国王一起是第3对,但如果有不同的套装则是第5对。
以下是我的代码现在的样子:
suit = str(input("suit 1"))
rank = int(input("rank 1"))
suit1 = str(input("suit 2"))
rank1 = int(input("rank 2"))
if rank == rank1:
if rank and rank1 == 13: # double ace
print("1/169")
elif rank and rank1 == 12: # double king
print("2/169")
elif rank and rank1 == 11: # double queen
print("3/169")
elif rank and rank1 == 10: # double jack
print("5/169")
elif rank and rank1 == 9: # double 10s
print("10/169")
elif rank and rank1 == 8: # double 9s
print("17/169")
elif rank and rank1 == 7: # double 8s
print("21/169")
elif rank and rank1 == 6: # double 7s
print("29/169")
elif rank and rank1 == 5: # double 6s
print("36/169")
elif rank and rank1 == 4: # double 5s
print("46/169")
elif rank and rank1 == 3: # double 4s
print("50/169")
elif rank and rank1 == 2: # double 3s
print("52/169")
elif rank and rank1 == 1: # double 2s
print("51/169")
然后基本上同样的东西与不同的西装和排名。显然这不是最好的方法,而且我不是最好的Python编码器,但还有其他更有效的方法吗?
答案 0 :(得分:0)
您的代码可以运行,但我们可以通过编写更少的代码和代码来改进它,这些代码和代码可以更容易地复制到pocker的其余组合中。试试这个:
suit = str(input("suit 1"))
rank = int(input("rank 1"))
suit1 = str(input("suit 2"))
rank1 = int(input("rank 2"))
scoring_of_doubles = [ [1,51], [2,52], [3,50], [4,46], [5,36], [6,29], [7,21], [8,17], [9,10], [10,5], [11,3], [12,2], [13,1] ]
if rank == rank1:
for sublist in scoring_of_doubles:
if sublist[0] == rank:
print("You've got a double, scored at: ")
print(sublist[1])
答案 1 :(得分:0)
我建议您使用dict
来保持组织有序:
output = {1: 51,
2: 52,
3: 50,
4: 46,
5: 36,
6: 29,
7: 21,
8: 17,
9: 10,
10: 5,
11: 3,
12: 2,
13: 1}
if rank == rank1:
print("{}/169".format(output[rank]))