我正在玩21点21点纸牌游戏,但我似乎无法再抽到第三张牌上。再加一张牌,再加上一张牌,再加上一张牌也会发生。在
抱歉,我还是不知道我在做什么。(用这个或Python)
import random
for deal in range(1,2):
card1=random.randrange(1,12)
card2=random.randrange(1,12)
if card1 == 1 or card1 == 11:
ace1 = int(input("Would you like a 1 or 11?"))
if ace1 == 1:
card1 = 1
elif ace1 == 11:
card1 = 11
else:
print "not a choice. P.S. I'm too lazy/don't know how to loop this, so you better restart"
print card1
if card2 == 1 or card2 == 11:
ace2 = int(input("Would you like a 1 or 11?"))
if ace2 == 1:
card2 = 1
elif ace2 == 11:
card2 = 11
else:
print "not a choice. P.S. I'm too lazy/don't know how to loop this, so you better restart"
print card2
hand = card1+card2
if hand == 21:
print "You win"
print "You're hand is", hand
elif hand > 21:
print "You busted"
print "You're hand is", hand
else:
print "You're hand is", hand
for deal in range(1,2):
dealer_card1=random.randrange(1,12)
dealer_card2=random.randrange(1,12)
dealer_cards=dealer_card1 + dealer_card2
print "The dealer has drawn his hand"
if dealer_cards == 21:
print "Dealer won"
elif dealer_cards > 21:
print "Dealer busted, you won"
else:
print "You're turn"
dealer_hand = [dealer_card1,dealer_card2]
player_hand = [card1,card2]
def draw():
draw = input("Would you like to [H]it or [S]tay?")
if draw == "h":
card3 = random.randrange(1,12)
if card3 == 1 or card3 == 11:
ace3 = int(input("Would you like a 1 or 11?"))
if ace3 == 1:
card3 = 1
elif ace3 == 11:
card3 = 11
else:
print "not a choice. P.S. I'm too lazy/don't know how to loop this, so you better restart"
print "You drew a", card3
hand1 = hand + card3
player_hand = [card1,card2,card3]
print hand1
if hand1 == 21:
print "You won"
elif hand1 > 21:
print "You busted"
elif hand1 > 15:
print "So close"
print "Dealer's turn"
print dealerdraw()
else:
print "you've got a way to go"
print "Dealer's turn"
print dealerdraw()
elif draw == "s":
if hand >= 16:
print "Nice play"
print "Dealer's turn"
print dealerdraw()
elif hand == 21:
print "You won"
else:
print "Not the best play"
print "Dealer's turn"
print dealerdraw()
else:
print "not a choice. P.S. I'm too lazy/don't know how to loop this, so you better restart"
return " "
def dealerdraw():
if dealer_cards < 21:
dealer_card3 = random.randrange(1,12)
dealer_hand = [dealer_card1,dealer_card2,dealer_card3]
dealer_cards1 = dealer_cards + dealer_card3
print "Dealer drew a card"
if dealer_cards1 == 21:
print "Dealer won"
print "his hand was", dealer_hand, "totaling", dealer_cards1
elif dealer_cards1 > 21:
print "Dealer busted, you won"
print "his hand was", dealer_hand, "totaling", dealer_cards1
else:
print "The Dealer smirks"
print "You're turn"
print draw()
elif dealer_cards == 21:
print "Dealer won, his hand was", dealer_hand, "totaling", dealer_cards1
else:
print "If you see this, the game isn't working"
return " "
print draw()
哇。。他们花了一段时间,但我想我终于成功了:)
在提供的代码中,
print
语句表明您正在使用python2,但是各种input()
调用似乎是python3。在我认为您使用的是python2,否则编译器将抱怨并且不会打印任何内容。在
在这种情况下,以pyhton2样式重写输入:
变成:
^{pr2}$类似于}函数中的
ace2
和{draw
。在python2中,input()
已经计算了输入,因此如果输入了一个整数,就已经得到了一个整数。在变成:
这可能就是问题所在。
input()
试着把字符串当作一个变量来处理,当然这是不存在的。在python2中,您需要raw_input()
来接受一个字符串作为输入。在我编辑了
dealerdraw()
来解决这一部分:庄家总是抽一张牌。但现在他手上的牌都加好了,或者他赢了21张,否则他就破产了。由你来改进代码,让经销商留下来。在
相关问题 更多 >
编程相关推荐