最高卡赢

时间:2018-11-24 11:12:12

标签: python

我创建了这个程序,无法判断哪张卡最高。有什么办法可以做到吗?

    from random import *

print("Highest card wins \n")
print("S = spades. \n H = hearts. \n C = clubs. \n D = diamonds. \n J = big joker. \n j = small joker. \n ")
P1= input("Press enter to draw your card \n" "Player One: ")

print("Player One drew ")
myList=(["Sk","Sq","Sj","Sa","S1","S2","S3", "S4","S5","S6","S7","S8","S9","J","j","Ck","Cq","Cj","Ca","C1","C2","C3", "C4","C5","C6","C7","C8","C9","Hk","Hq","Hj","Ha","H1","H2","H3", "H4","H5","H6","H7","H8","H9","Dk","Dq","Dj","Da","D1","D2","D3", "D4","D5","D6","D7","D8","D9"])

y = sample(myList, 1)
print (y)

P2=input("Press enter to draw your card \n" "Player Two: ")

print("Player Two drew ")
myList=(["Sk","Sq","Sj","Sa","S1","S2","S3", "S4","S5","S6","S7","S8","S9","J","j","Ck","Cq","Cj","Ca","C1","C2","C3", "C4","C5","C6","C7","C8","C9","Hk","Hq","Hj","Ha","H1","H2","H3", "H4","H5","H6","H7","H8","H9","Dk","Dq","Dj","Da","D1","D2","D3", "D4","D5","D6","D7","D8","D9"])


y = sample(myList, 1)
print (y)

if P1 < P2:
    print("Player One Loses ")
else:
    print("Player Two Wins ")

2 个答案:

答案 0 :(得分:1)

我假设卡的值与其顺序相对应。 王牌是一,国王是13。 J是14,j是0 这里有抽奖的机会

{%for row in odata%}
    <div class="options">
      <label>
        {{row}} <input type="radio" name="option-text">
      </label>
    </div>
{%endfor%}

答案 1 :(得分:0)

这是我要用较小的纸牌来做的事情。如果您想用一个完整的甲板制作它,只需订购就可以了。如果您拥有相同功率的卡,则可以将其放在列表内的列表中,但是如果您选择一个,则必须想出一种从该嵌套列表中打印卡的方法。

from random import choice

print("Highest card wins \n")
P1= input("Press enter to draw your card \n" "Player One: ")

print("Player One drew ")
player_1_deck = ['c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] #sample deck, ordered in ascending order of strenght, the higher the index of the card on the list, the stronger it is

p1_draw = choice(player_1_deck) #chooses a random card from player 1 deck
print (p1_draw) #print selected card
p1_draw_streght = player_1_deck.index(p1_draw) #store the strenght of the card an integer variable for later comparing with player 2

P2=input("Press enter to draw your card \n" "Player Two: ") 

print("Player Two drew ")
player_2_deck = ['c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] #same process for player 2

p2_draw = choice(player_2_deck)
print (p2_draw)
p2_draw_streght = player_2_deck.index(p2_draw)

if p1_draw_streght < p2_draw_streght: #comparing strenghts
    print("Player Two Wins ")
elif p1_draw_streght == p2_draw_streght:
    print('Draw')
else:
    print("Player One Wins ")