我在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
代码正在完全按照我的要求(即打印行)。如何让它打印一次,然后重新启动并处理新卡。
答案 0 :(得分:7)
将读取dealer
和player
指针的代码移至循环开头:
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