【发布时间】:2012-09-21 07:05:25
【问题描述】:
def deck():
cards = range(1, 12)
return choice(cards)
def player():
card1 = deck()
card2 = deck()
hand = card1 + card2
print card1, card2
while hand < 21:
choice = raw_input("Would you like to hit or stand?: ")
print choice
if choice == "hit":
hand2 = hand + deck()
print hand2
elif choice == "stand":
return hand
大家好,
我正在尝试用 python 制作一个简单的二十一点游戏。我已经走到这一步了,我似乎被困住了。当我尝试弹奏时,它会询问我是否要击打或站立哪个好;但是,我的问题是它似乎每次都在生成新的卡值。这意味着如果我击中而不是站立,它将返回原始值而不是三张牌的新值。
您可以告诉我,我是编程新手,因此非常感谢任何帮助,我希望尽可能多地使用我自己的代码。
【问题讨论】:
-
你真的需要制作一副 52 张牌...
标签: python if-statement python-2.7