Listing 10-01: Account with transaction log and statement (accounts

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 10\10.01 - Account with transaction log and statement (accounts.py).py
# Description: Account with transaction log and statement (accounts.py)
##############################################################################

class Account:
    def __init__(self, clients, number, balance=0):
        self.balance = 0
        self.clients = clients
        self.number = number
        self.operations = []
        self.deposit(balance)
    def summary(self):
        print(f"Account #{self.number} Balance: {self.balance:10.2f}")
    def serve(self, value):
        if self.balance >= value:
            self.balance -= value
            self.operations.append(["WITHDRAW", value])
    def deposit(self, value):
        self.balance += value
        self.operations.append(["DEPOSIT", value])
    def statement(self):
        print(f"Account Statement #{self.number}\n")
        for operation in self.operations:
            print(f"{operation[0]:10s} {operation[1]:10.2f}")
        print(f"\n    Balance: {self.balance:10.2f}\n")
Click here to download the file