-1
import random
cards_names = {1: "Ace", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8",
9: "9", 10: "10", 11: "Jack", 12: "Queen", 13: "King"}
def dealing():
return random.randint(1, 13)
def value_of_hand(cards):
value = 0
for card in cards:
if 1 < card <= 10:
value += card
elif card > 10:
value += 10
if 1 in cards and value + 11 <= 21:
return value + 11
elif 1 in cards:
return value + 1
else:
return value
def your_hand(name , cards):
faces = [cards_names[card] for card in cards]
value = value_of_hand(cards)
if value == 21:
print ("Wow, you got Blackjack!")
else:
print ("")
print ("%s's hand: %s, %s : %s %s") % (name, faces[0], faces[1], value)
for name in ("Dealer", "Player"):
cards = (dealing(), dealing())
your_hand(name, cards)
我給你一個你很可能想得到的答案,但爲了將來的參考,我建議你閱讀[如何問](http://stackoverflow.com/help/how-to-ask)。簡而言之:準確地說明您遇到的錯誤,您遇到問題的部分代碼以及代碼所需的行爲。歡迎來到Stackoverflow! –