3

我正在用 python 制作游戏,但遇到了创建无限的问题。我是编程新手,我不知道如何解决它。任何帮助都会很棒。

money = 100
opp = dealer()
me = player()

while money > 0:
if me > opp:
    money = money * 1.5
    print "Winner, winner, chicken dinner! You have $%d!" % money
elif opp > me:
    money = money * 0.75
    print "Dealer wins with %d. You have $%d reamaining." % (opp, money)
elif me == 21:
    money = money * 1.5
    print "Blackjack! You have $%d!" % money

该代码完全按照我的要求执行(即打印该行)。我怎样才能让它打印一次,然后重新启动并处理新卡。

4

1 回答 1

7

将读取dealerplayer手的代码移动到循环的开头:

while money > 0:
  opp = dealer()
  me = player()
  if me > opp:
    money = money * 1.5
    print "Winner, winner, chicken dinner! You have $%d!" % money
  elif opp > me:
    money = money * 0.75
    print "Dealer wins with %d. You have $%d reamaining." % (opp, money)
  elif me == 21:
    money = money * 1.5
    print "Blackjack! You have $%d!" % money
于 2012-09-29T21:20:50.060 回答