def withdraw(self, amount): """Restricts number of withdrawaks to MAX_WITHDRAWALS.""" if self.counter == RestrictedSavingsAccount.MAX_WITHDRAWALS: return 'No more withdrawals this month' else: message = SavingsAccount.withdraw(self, amount) if message == None: self.counter += 1 return message
def withdraw(self, amount): if self.counter == \ RestrictedSavingsAccount.MAX_WITHDRAWALS: return "Withdrawls maxed out for month" else: message = SavingsAccount.withdraw(self, amount) if message == None: self.counter += 1 return message
def createBank(numAccounts=1): names = ("Alex", "Arsene", "Ryuji", "Ann", "Makoto", "Akechi", "Lucy", "Haru") bank = Bank() upperPin = numAccounts + 1000 for pinNumber in range(1000, upperPin): name = random.choice(names) balance = float(random.randint(100, 1000)) bank.add(SavingsAccount(name, str(pinNumber), balance)) return bank
def createBank(numAccounts=1): """Returns a new bank with the given number of accounts.""" names = ("Brandon", "Molly", "Elena", "Mark", "Tricia", "Ken", "Jill", "Jack") bank = Bank() upperPin = numAccounts + 1000 for pinNumber in range(1000, upperPin): name = random.choice(names) balance = float(random.randint(100, 1000)) bank.add(SavingsAccount(name, str(pinNumber), balance)) return bank
def createBank(number=None): import random bank = Bank() if number > 0: for i in range(number): bank.add( SavingsAccount( "Account " + str(i), ''.join([str(random.randint(1, 9)) for _ in range(4)]), balance=random.randint(1, 10) * 1000)) return bank else: return None
def testAccount(): """Test function for savings account.""" account = SavingsAccount("Ken", "1000", 500.00) print(account) print(account.deposit(100)) print("Expect 600:", account.getBalance()) print(account.deposit(-50)) print("Expect 600:", account.getBalance()) print(account.withdraw(100)) print("Expect 500:", account.getBalance()) print(account.withdraw(-50)) print("Expect 500:", account.getBalance()) print(account.withdraw(100000)) print("Expect 500:", account.getBalance())
def __init__(self, name, pin, balance=0.0): """Wrap a new account in a shared cell for thread-safety.""" account = SavingsAccount(name, pin, balance) self.cell = SharedCell(account)
def __init__(self, name, pin, balance=0.0): """Same attributes as SavingsAccount, but with a counter for withdrawals.""" SavingsAccount.__init__(self, name, pin, balance) self.counter = 0
def __init__(self, name, pin, balance=0.0): SavingsAccount.__init__(self, name, pin, balance) self.counter = 0
"""" For this question, you need to refer to class Account and class SavingsAccount from the Module for "Week 7 : Inheritance" Write a call to the __int__() method (from the previous question) on an object of class SavingsAccount. You need to provide both the code that creates an object of class SavingsAccount and the code that calls the __int__() method in order to test it. """ from savingsaccount import SavingsAccount a = SavingsAccount() a.balance = 1000 print(a) print(a.__int__()) print(int(a))
def testAccount(): account = SavingsAccount("Alex", "1000", 500.00) print(account) print(account.deposit(100)) print("Expect 600:", account.getBalance()) print(account.deposit(-50)) print("Expect 600:", account.getBalance()) print(account.withdraw(100)) print("Expect 500:", account.getBalance()) print(account.withdraw(-50)) print("Expect 500:", account.getBalance()) print(account.withdraw(100000)) print("Expect 500:", account.getBalance())
#!/usr/local/bin/python from account import Account from savingsaccount import SavingsAccount account1 = Account(1000.00) account1.deposit(550.23) print(account1.getbalance()) another = SavingsAccount(0, 3) print('objects:', Account.numCreated) print("object another is class", another.__class__.__name__)