Skip to content

Instantly share code, notes, and snippets.

@letuananh
Created March 11, 2015 03:53
Show Gist options
  • Save letuananh/44b730ed5955392f6067 to your computer and use it in GitHub Desktop.
Save letuananh/44b730ed5955392f6067 to your computer and use it in GitHub Desktop.

Revisions

  1. letuananh renamed this gist Mar 11, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. letuananh created this gist Mar 11, 2015.
    30 changes: 30 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    class BankAccount:

    def __init__(self, initial_balance=0):
    self.balance = initial_balance

    def deposit(self,amount):
    self.balance += amount
    print("Depositted %s" % (amount,))

    def withdraw(self, amount):
    if amount > self.balance:
    print("Failed to withdraw %s. You don't have enough cash." % (amount,))
    else:
    self.balance -= amount
    print("Withdrawn %s" % (amount,))

    def get_balance(self):
    return self.balance

    def main():
    print("Banking demo")
    b=BankAccount()
    b.deposit(5000)
    b.deposit(3000)
    b.withdraw(10000)
    b.withdraw(2000)
    print("Current balance: %s" % (b.get_balance(),))

    if __name__ == "__main__":
    main()