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.
Bank account demo
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment