Python - Black Jack Program
<p>I am creating a black jack game in python. How do I move the ending money variable to the top of the function as the function loops?</p>

<pre><code>print "Welcome to BlackJack"

def run():

    import random
    from random import choice
    import sys
    money = 500
</code></pre>

<p>The variable 'money' changes depending if the play wins or loses. I want the ending variable to become the beginning variable when the play selected play again.</p>

<pre><code>    raw_input("Press &lt;ENTER&gt; To Begin")
    print "You have $",money,"in your bank."
    bet = raw_input("How much would you like to bet?")

    b = int(bet)

    cards = [1,2,3,4,5,6,7,8,9,10,10,10,10]*4

    c1 = choice(cards)
    cards.remove(c1) 

    c2 = choice(cards)
    cards.remove(c2)

    psum = c1 + c2

    print "You were dealt a",c1,"and a",c2,"for a sum of",psum,
    print "\n"
    hs = " "

    while psum &lt; 21 and "s" not in hs:
        hs = raw_input("Hit or Stand (h or s): ").lower()
        if "h" in hs:
            c3 = choice(cards)
            cards.remove(c3)
            psum = psum + c3
            print "You were dealt a",c3,"for a sum of",psum,
            print "\n"
        elif "s" in hs:
            print "Your final sum is",psum,

    print "\n"

    if psum &gt; 21:
        print "Bust!" "\n" "You lose." "\n"
        money = money - b
        print "You now have $",money,"in your bank."
    elif psum == 21:
        print "You got a BlackJack!" "\n" "You win!" "\n"
        money = money + b
        print "You now have $",money,"in your bank."   
    else:
        print "Dealer's turn"

    if psum &lt; 21:   
        c4 = choice(cards)
        cards.remove(c4) 

        c5 = choice(cards)
        cards.remove(c5)

        dsum = c4 + c5

        while dsum &lt; 17:
            c6 = choice(cards)
            cards.remove(c6)
            dsum = dsum + c6

        if dsum &gt; 21:
            print "Dealer's final sum is",dsum,"\n"
            print "Dealer bust! You win!" "\n"
            money = money + b
            print "You now have $",money,"in your bank."
        elif dsum &lt; psum:
            print "Dealer's final sum is",dsum,"\n"
            print "You win!" "\n"
            money = money + b
            print "You now have $",money,"in your bank."
        elif dsum == psum:
            print "Dealer's final sum is",dsum,"\n" 
            print "Draw." "\n"
            print "You have $",money,"in your bank."
        else:
            print "Dealer's sum is",dsum,"\n"
            print "You lose." "\n"
            money = money - b
            print "You now have $",money,"in your bank."


    yn = raw_input("Would you like to play again? (y or n): ")

    if "y" in yn:
        print "\n" * 5
        run()
    else:
        print "\n" "Your total winnings is $",money,
        sys.exit()          

run()      
</code></pre>
