July project night/OO lesson/banking2.py
class Bank:
def __init__(self): self.usernamesPasswordsDictionary = {} def addUser(self, user): self.usernamesPasswordsDictionary[user.username] = user.password print "Bank added user " + user.username + " to un/pw dictionary" 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 addMoney(self, amount): self.balance = self.balance + amount print "Account just added %d bucks; new balance is: %d" % (amount, self.balance)
def withdrawMoney(self, amount): self.balance = self.balance - amount print "Account just withdrew %d bucks; new balance is: %d" % (amount, self.balance)