"""Ex. 6.9 in 'A primer on...' Extend the Account class with an additional attribute counting the number of transactions, and write a test function to test the class methods. """ class Account: def __init__(self, name, number, balance): self.name = name self.number = number self.balance = balance self.transactions = 1 def deposit(self, amount): self.balance += amount self.transactions += 1 def withdraw(self, amount): self.balance -= amount self.transactions += 1 def print_info(self): name = self.name number = self.number bal = self.balance trans = self.transactions s = f'{name}, {number}, balance: {bal}, transactions = {trans}' print(s) """Simple test function setup for a class: 1. Create one or more instances 2. Call one or more methods 3. Assert that results are as expected.""" def test_Account(): a = Account('js', 12345, 1000) a.withdraw(50) a.deposit(100) assert a.balance == 1050 assert a.transactions == 3 if __name__ == "__main__": test_Account() a1 = Account('John Olsson', '19371554951', 20000) a2 = Account('Liz Olsson', '19371564761', 20000) a1.deposit(1000) a1.withdraw(4000) a2.withdraw(10500) a1.withdraw(3500) print("a1's balance:", a1.balance) a1.print_info() """ Terminal> python Account2.py a1's balance: 13500 John Olsson, 19371554951, balance: 13500, transactions = 4 """