""" Exercise 7.3 from "A primer on..." Add a list of transactions as an attribute in the AccountP class. Remove the _balance attribute, and instead calculate the balance directly from the list of transactions. Solution strategy (to ensure new calculation is working before removing the old): 1. Add the transactions list and the code to update it (in __init__, deposit and withdraw) 2. Add the code to calculate the balance based on the new list 3. Make sure the new balance calculations matches the old 4. Remove self._balance and the related updates 5. Add print_transactions """ from datetime import datetime class AccountP: def __init__(self, name, account_number, initial_amount): self._name = name self._no = account_number self._transactions = [{'time':datetime.now(), 'amount': initial_amount}] def deposit(self, amount): self._transactions.append({'time':datetime.now(), 'amount': amount}) def withdraw(self, amount): self._transactions.append({'time':datetime.now(), 'amount': -amount}) def get_balance(self): # NEW - read balance value bal = 0 for t in self._transactions: bal += t['amount'] return bal def print_transactions(self): for t in self._transactions: time = t['time'] amount = t['amount'] print(f"{time.strftime('%c')}: {amount}") def dump(self): s = f'{self._name}, {self._no}, balance: {self.get_balance()}' print(s) a1 = AccountP('John Olsson', '19371554951', 20000) a2 = AccountP('Liz Olsson', '19371564761', 20000) a1.deposit(1000) a1.withdraw(4000) a2.withdraw(10500) a1.withdraw(3500) print(a1.get_balance()) a1.print_transactions() a2.dump() """ Terminal> python Account3.py 13500 Mon Oct 20 16:22:51 2025: 20000 Mon Oct 20 16:22:51 2025: 1000 Mon Oct 20 16:22:51 2025: -4000 Mon Oct 20 16:22:51 2025: -3500 Liz Olsson, 19371564761, balance: 9500 """