tdunham99

bankaccount

Jul 12th, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. class BankAccount():
  2.     balance = 0
  3.     def __init__(self, name):
  4.         self.name = name
  5.     def __repr__(self):
  6.         return("Owner of account: %s. Balance: $%.2d" % (self.name, self.balance))
  7.     def show_balance(self):
  8.         return "Balance: %.2d" % self.balance
  9.     def deposit(self, amount):
  10.         if amount <= 0:
  11.             print("Invalid amount!")
  12.             return
  13.         else:
  14.             print("Depositing $%.2d" % amount)
  15.             self.balance += amount
  16.             self.show_balance()
  17.     def withdraw(self, amount):
  18.         if amount > self.balance:
  19.             print("Invalid amount!")
  20.             return
  21.         else:
  22.             print("Withdrawing $%.2d" % amount)
  23.             self.balance -= amount
  24.             self.show_balance()
  25.  
  26. my_account = BankAccount("Tristan")
  27. print(my_account)
  28. print(my_account.show_balance())
  29. print(my_account.deposit(2000))
  30. print(my_account.withdraw(1000))
  31. print(my_account)
Add Comment
Please, Sign In to add comment