
# LotsOfDeals plays a coin-flip game that lets a player try
#  repeatedly to double their money until they quit or lose.
# Input: the player's decisions about flipping a coin
# Output: the amount the player won.

import random
money = random.randrange(1,101)
print "You start with", money, "dollars."

game_on = True # remembers if the game is still going on

while game_on :
    # assert: game_on,  and  money  remember the winnings so far

    response = raw_input("Do you want to try to double your money (y or n)? ")

    if response == "n" :    # player wants to quit
        game_on = False

    elif response == "y":   # player wants to flip a coin
        coinflip = random.randrange(0,2) 
        if coinflip == 1 :  # a winner
            money = money * 2
            print "Congratulations! You won $", money
        else :              # coinflip == 0 --- a loser
            money = 0
            print "Sorry --- you lost!"
            game_on = False

    else :                  # bad input response
        print "Sorry, bad input.  Game's over."
        game_on = False

# assert: not game_on,  and  money  remembers the final winnings.

print "You leave with $" + str(money) + "!"
raw_input("\nPress Enter to quit")
