Created
March 11, 2015 03:53
-
-
Save letuananh/44b730ed5955392f6067 to your computer and use it in GitHub Desktop.
Bank account demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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