class Portfolio(): def __init__(self): self._checkings = BankAccount() self._savings = BankAccount() def get_balance(self, account): if account == "C": self._checkings.getBalance() elif account == "S": self._savings.getBalance() def deposit(self, amount, account): if account == "C": self._checkings.deposit(amount) elif account == "S": self._savings.deposit(amount) def withdraw(self, amount, account): if account == "C": self._checkings.withdraw(amount) elif account == "S": self._savings.withdraw(amount) def transfer(self, amount, account): if account == "C": amount_to_transfer = self._checkings.withdraw(amount) self._savings.deposit(amount_to_transfer) elif account == "S": amount_to_transfer = self._savings.withdraw(amount) self._checkings.deposit(amount_to_transfer)
class Portfolio: def __init__(self): self._checking = BankAccount() self._saving = BankAccount() def withdraw(self, amount, account): if account.upper() == 'C': self._checking.withdraw(amount) else: self._saving.withdraw(amount) def deposit(self, amount, account): if account.upper() == 'C': self._checking.deposit(amount) else: self._saving.deposit(amount) def transfer(self, amount, account): if account.upper() == 'C': self._checking.withdraw(amount) self._saving.deposit(amount) else: self._saving.withdraw(amount) self._checking.deposit(amount) def getBalance(self, account): if account.upper() == 'C': return self._checking.getBalance() else: return self._saving.getBalance()
def index(): user = BankAccount(session['username'], 0) rec_trans = [] for x in user.recents(): a, b, c = x fromz = tz.tzutc() toz = tz.tzlocal() utc = datetime.strptime(b, '%Y-%m-%d %H:%M:%S.%f') utc = utc.replace(tzinfo=fromz) b = utc.astimezone(toz) rec_trans.append([ str(b.date()) + ' ' + str(b.hour) + ':' + str(b.minute) + ':' + str(b.second), str(c) ]) rec_trans = list(reversed(rec_trans))[0:9] return render_template('index.html', amount=str(user.getBalance()), username=session['username'], recents=convert(rec_trans))
## # This program tests the BankAccount class. # from bankaccount import BankAccount harrysAccount = BankAccount(1000.0) harrysAccount.deposit(500.0) # Balance is now $1500 harrysAccount.withdraw(2000.0) # Balance is now $1490 harrysAccount.addInterest(1.0) # Balance is now $1490 + 14.90 print("%.2f" % harrysAccount.getBalance()) print("Expected: 1504.90")