
# LotsOfDeals plays a coin flip game that lets a player try
#  repeatedly to double their money until they quit or lose
# assumed input: the player's decisions about flipping a coin
# guaranteed 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 alive

while game_on :
    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

# At this point, the game has ended (the loop has finished):
print "You leave with $" + str(money) + "!"
raw_input("\nPress Enter to quit")
