Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python infinite loop [closed]

I am making a game in python and I have encountered a problem where an infinite has been created. I'm new to programming and I'm not sure how to fix it. Any help would be amazing.

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

The code is doing exactly what I've asked from it (which is to print the line). How can I make it print the line once and then just restart and deal new cards.

like image 560
iamtesla Avatar asked Mar 02 '26 06:03

iamtesla


1 Answers

Move the code that reads the dealer and the player hands to the beginning of loop:

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
like image 185
João Silva Avatar answered Mar 03 '26 20:03

João Silva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!