有没有一种简单的方法可以为列表中的卡片提供一组积分?

时间:2019-01-22 09:51:22

标签: python python-3.x blackjack playing-cards

我的任务是在python中创建一个非常简单的Blackjack版本,在这里您问他们是否要玩,他们说是,然后抓了一张卡,它说出了您选择后的点数卡,然后询问您是否要再次玩。我在实施“积分系统”时需要帮助。

我尝试做一些if语句,如果列表中有数字,它将给它与它相同的分数,但是我发现它不起作用。

import random

nummer = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "Kung", "Dam", 
"Knekt", "Ess"]
kort = ["♦", "♥", "♣", "♠"]
kortlek = []
for n in range(0, 4):
    for x in range(0, 13):
        kortlek.append(kort[n] + " " + nummer[x])

d_k = []

svar = input("Do you want to play? (y/n) ")

if svar == "y":
    drag = random.choice(kortlek)
    print("You got ", drag)
    d_k.append(drag)
    kortlek.remove(drag)
else:
    print("Bye")

基本上我想要它,以便在您绘制一张牌后,它会告诉您总积分。

1 个答案:

答案 0 :(得分:-1)

如@ TigerhawkT3的评论中所述,将jobid做成字典,每张卡片都具有它的卡值。

kortlek

您可以美化输出并自行格式化输出,然后从这里继续。祝好运! :)

EDIT :另外请注意,在二十一点游戏中,Ace(“ Ess”)可以是1或11。我没有帮助您编写代码,但是您应该可以实现使用import random nummer = ["Ess", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Knekt", "Dam", "Kung"] # Kung = king, dam = queen, knekt = jack, ess = ace (assumed) kort = ["♦", "♥", "♣", "♠"] kortlek = {} # (Card choice : Value) using dictionary for n in range(0, 4): # Can remove "0, " for x in range(0, 13): # Can remove "0, " kortlek[kort[n] + " " + nummer[x]] = x + 1 d_k = [] svar = input("Do you want to play? (y/n) ") if svar == "y": drag = random.choice(list(kortlek.keys())) print("You got ", drag, "which has a card value of:", kortlek[drag]) d_k.append(drag) del kortlek[drag] else: print("Bye") 循环:)

Test it Yourself