# ATM  lets a human withdraw cash from an automated teller machine.

def errorMessage(message) :
    """errorMessage  prints a specific error message.
    
       parameter: message - a string, stating the error
    """
    text = "Error: " + message
    print  text + " Sorry.\n"


def formatCents(amount) :
    """formatCents  formats a cents amount into a 
          $dollars.cents   string

       parameter: amount - a nonegative int, a cents-only amount
       returns: a string, formatted as  "$dollars.cents" 
         (If  amount  is < 0, then the string, "negative" is returned.)

       Example: for amount = 1203,  answer = "$12.03"
    """
    if amount >= 0 :
        dollars = amount / 100
        cents = amount % 100
        answer = "$" + str(dollars) + "." 
        if cents < 10 :
            answer = answer + "0" + str(cents)
        else :
            answer = answer + str(cents)
    else :
        answer = "negative"
    return answer


####### The program starts here:

OK = True  # remembers if the transaction is proceeding OK

account = int(raw_input("Type your account number (or slide your card): "))

dollars = int(raw_input("Type dollars amount: "))
if dollars < 0 :
    errorMessage("You typed a negative number.")
    OK = False

if OK :
    cents = int(raw_input("Type cents amount: "))
    if (cents < 0) or (cents > 99) :
        errorMessage("The cents amount was not in the range 0..99.") 
        OK = False

if OK :
    request = (dollars * 100) + cents
    print "Request to withdraw " + formatCents(request)

    print "...withdraw the cash from the account...(to come)"

    # Contact bank's database to withdraw the  request :

    # import BankDatabase
    # cash = BankDatabase.withdraw(account, request)

    #   BankDatabase is another file -- a module -- that
    #   holds the bank's database and function  withdraw   
    #   ( Think of  random.randrange(...)  )  

    # Emit cash ...

raw_input("press Enter to finish")
