Relative Content

Tag Archive for pythonaccount

ValueError exception in Transaction

class BankAccount: def __init__(self, account_number, balance=0): self.account_number = account_number self.balance = balance def deposit(self, amount): self.balance += amount def withdraw(self, amount): if amount > self.balance: raise ValueError(“Insufficient funds”) self.balance -= amount def get_balance(self): return self.balance class Transaction: def __init__(self, account, amount): self.account = account self.amount = amount def execute(self): try: self.account.withdraw(self.amount) except ValueError as e: […]