Python21纸牌游戏问题

Python21纸牌游戏问题,python,Python,我正在玩21点/21张牌的游戏,当我再次抽签时,我似乎无法将它添加到添加的第三张牌上。这种情况也会发生在庄家身上,他只是陷入了一个无休止的循环:抽一张牌,取出前一张牌,然后再加上那张牌 对不起,格式太糟糕了,我还是不知道我在做什么。(使用this或Python) 随机导入 对于范围(1,2)内的交易: card1=随机随机随机范围(1,12) card2=随机随机随机范围(1,12) 如果card1==1或card1==11: ace1=int(输入(“您想要1还是11?”) 如果ace1==1

我正在玩21点/21张牌的游戏,当我再次抽签时,我似乎无法将它添加到添加的第三张牌上。这种情况也会发生在庄家身上,他只是陷入了一个无休止的循环:抽一张牌,取出前一张牌,然后再加上那张牌

对不起,格式太糟糕了,我还是不知道我在做什么。(使用this或Python)

随机导入
对于范围(1,2)内的交易:
card1=随机随机随机范围(1,12)
card2=随机随机随机范围(1,12)
如果card1==1或card1==11:
ace1=int(输入(“您想要1还是11?”)
如果ace1==1:
card1=1
elif ace1==11:
card1=11
其他:
打印“没有选择。另外,我太懒了/不知道如何循环,所以你最好重新启动”
打印卡1
如果card2==1或card2==11:
ace2=int(输入(“您想要1还是11?”)
如果ace2==1:
card2=1
elif ace2==11:
card2=11
其他:
打印“没有选择。另外,我太懒了/不知道如何循环,所以你最好重新启动”
打印卡片2
手动=卡1+卡2
如果手=21:
打印“你赢了”
打印“你的手是”,手
elif hand>21:
打印“你被抓到了”
打印“你的手是”,手
其他:
打印“你的手是”,手
对于范围(1,2)内的交易:
经销商卡1=随机。随机范围(1,12)
经销商卡2=随机。随机范围(1,12)
经销商卡=经销商卡1+经销商卡2
打印“经销商已拉手”
如果经销商卡==21:
打印“经销商赢了”
elif经销商卡>21:
打印“经销商破产,你赢了”
其他:
打印“轮到你了”
经销商牌=[经销商牌1,经销商牌2]
玩家手=[card1,card2]
def draw():
draw=输入(“您是要[H]它还是[S]泰伊?”)
如果绘图=“h”:
card3=随机随机随机范围(1,12)
如果card3==1或card3==11:
ace3=int(输入(“您想要1还是11?”)
如果ace3==1:
card3=1
elif ace3==11:
card3=11
其他:
打印“没有选择。另外,我太懒了/不知道如何循环,所以你最好重新启动”
打印“你画了一张”,卡片3
手1=手+卡3
玩家手=[card1,card2,card3]
打印手册1
如果hand1==21:
打印“你赢了”
elif hand1>21:
打印“你被抓到了”
elif hand1>15:
打印“如此接近”
打印“经销商的轮到”
打印DealDraw()
其他:
打印“你还有路要走”
打印“经销商的轮到”
打印DealDraw()
elif draw==“s”:
如果手动>=16:
打印“好戏”
打印“经销商的轮到”
打印DealDraw()
elif hand==21:
打印“你赢了”
其他:
打印“不是最好的剧本”
打印“经销商的轮到”
打印DealDraw()
其他:
打印“没有选择。另外,我太懒了/不知道如何循环,所以你最好重新启动”
返回“”
def dealderDraw():
如果经销商卡<21:
经销商卡3=随机。随机范围(1,12)
经销商牌=[经销商牌1、经销商牌2、经销商牌3]
经销商卡1=经销商卡+经销商卡3
打印“经销商抽卡”
如果经销商卡1==21:
打印“经销商赢了”
打印“他的手是”,经销商手,“总计”,经销商卡1
elif经销商卡1>21:
打印“经销商破产,你赢了”
打印“他的手是”,经销商手,“总计”,经销商卡1
其他:
打印“经销商的微笑”
打印“轮到你了”
打印绘图()
elif经销商卡==21:
打印“经销商赢了,他的手是”,经销商手,“总计”,经销商卡1
其他:
打印“如果你看到这个,游戏不起作用”
返回“”
打印绘图()

哇。。em这花了一段时间,但我想我终于让它工作了:)

随机导入
手=0
def draw():
全球手
手=0
draw=输入(“您是要[H]它还是[S]泰伊?”)
如果绘图=“h”:
card3=随机随机随机范围(1,12)
如果card3==1或card3==11:
ace3=int(输入(“您想要1还是11?”)
如果ace3==1:
card3=1
elif ace3==11:
card3=11
其他:
打印(“不是一个选择。另外,我太懒了/不知道如何循环这个,所以你最好重新启动”)
打印(“你画了一张”,卡片3)
手1=手+卡3
玩家手=[card1,card2,card3]
印刷品(手工1)
如果hand1==21:
打印(“您赢了”)
elif hand1>21:
打印(“你被抓到了”)
elif hand1>15:
打印(“如此接近”)
打印(“经销商轮到”)
打印(dealerdraw())
其他:
打印(“你还有路要走”)
打印(“经销商轮到”)
打印(dealerdraw())
elif draw==“s”:
如果手动>=16:
打印(“好戏”)
打印(“经销商轮到”)
打印(dealerdraw())
elif hand==21:
打印(“您赢了”)
其他:
打印(“不是最好的剧本”)
打印(“经销商轮到”)
打印(dealerdraw())
其他:
打印(“不是一个选择。另外,我太懒了/不知道如何循环这个,所以你最好重新启动”)
def dealderDraw():
全球经销商卡
全球手
如果经销商卡<21:
经销商卡3=随机。随机范围(1,12)
经销商卡+=经销商卡3
打印(经销商卡)
经销商卡1=经销商卡+经销商卡3
打印(“经销商绘制了一张卡”,经销商卡)
如果经销商卡==21:
打印(“经销商赢得”)
打印(“他的手是”,经销商手,“总计”,经销商卡1)
elif经销商卡>21:
打印(“经销商破产,你赢了”)
打印(“他的手是”,经销商手,“总计”,经销商卡1)
其他:
如果手牌>经销商卡:
打印(“您赢了”)
其他:
打印(“经销商赢了”)
elif经销商卡==21:
打印(“经销商赢了,他的手是”,经销商手,“总计”,经销商卡1)
其他:
打印(“如果你看到这个,游戏不起作用”)
尽管如此:
对于范围(1,2)内的交易:
card1=随机随机随机范围(1,12)
card2=随机随机随机范围(1,12)
如果card1==1或card1==11:
ace1=int(输入(“您想要1还是11?”)
如果ace1==1:
card1=1
elif ace1==11:
card1=11
其他:
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()
import random

hand = 0

def draw():
  global hand
  hand = 0
  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")



def dealerdraw():
  global dealer_cards
  global hand
  if dealer_cards < 21:

    dealer_card3 = random.randrange(1,12)

    dealer_cards += dealer_card3

    print (dealer_cards)
    dealer_cards1 = dealer_cards + dealer_card3

    print ("Dealer drew a card of", dealer_cards)

    if dealer_cards == 21:

      print ("Dealer won")

      print ("his hand was", dealer_hand, "totaling", dealer_cards1)


    elif dealer_cards > 21:

      print ("Dealer busted, you won")

      print ("his hand was", dealer_hand, "totaling", dealer_cards1)


    else:
      if hand > dealer_cards:
        print("you won")
      else: 
        print ("The Dealer won")

  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")




while True:
    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 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 of", dealer_cards)

      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]



    draw()
    print("---NEW GAME---")
ace1 = int(input("Would you like a 1 or 11?"))
ace1 = input("Would you like a 1 or 11?")
draw = input("Would you like to [H]it or [S]tay?")
draw = raw_input("Would you like to [H]it or [S]tay?")
def dealerdraw():
    global dealer_cards
    if dealer_cards < 21:
        dealer_card3 = random.randrange(1,12)
        dealer_hand.append(dealer_card3) #add the card to the dealer's list cards
        dealer_cards = sum(dealer_hand) #get the sum of all the cards
        print dealer_hand #just to show that cards in dealer hands are added, remove this line in real game
        print "Dealer drew a card"
        if dealer_cards == 21:
            print "Dealer won"
            print "his hand was", dealer_hand, "totaling", dealer_cards
        elif dealer_cards > 21:
            print "Dealer busted, you won"
            print "his hand was", dealer_hand, "totaling", dealer_cards
        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_cards
    else:
        print "If you see this, the game isn't working"
    return " "