Banking3.py
class Bank:
def __init__(self): self.usernamesPasswordsDictionary = {} def add_user(self, username, password): user = User(username, password) self.usernamesPasswordsDictionary[user.username] = user.password print "Bank added user: " + user.username return user def add_account(self, user): account = Account(user) print "Bank added account " + account.user.username + " with %d bucks" % (account.balance) return account def login(self, username, password): if self.usernamesPasswordsDictionary[username] == password: return True print "Bank could not log you in." return False
class User:
def __init__(self, theUsername, thePassword): self.username = theUsername self.password = thePassword
class Account:
def __init__(self, user): self.balance = 0 self.user = user def add_money(self, amount): self.balance = self.balance + amount print "Account just added %d bucks; new balance is: %d" % (amount, self.balance) def withdraw_money(self, amount): self.balance = self.balance - amount print "Account just withdrew %d bucks; new balance is: %d" % (amount, self.balance)