Mar-09-2022, 02:15 PM
(Mar-09-2022, 01:08 PM)Drone4four Wrote: How would you better formulate the try/except mechanism to catch transactions which don’t allow the user to go below $0.00?
To answer my own question, this seems to be an improvement and puts me closer to getting my ATM machine to behave as intended:
def withdraw(self, balance, amount): if (balance - amount) <= 0: raise ValueError('Transaction declined. Insufficient funds. Deposit some money first.') withdraw(self, balance, amount) else: return balance - amount