I'm confused by your code structure. That looks like many MANY different classes worth of work to me! I don't have time to write up something more fully-formed, but consider refactoring your code, especially consider that the __init__
method should initialize all the ATTRIBUTES of a class, which would include things like self.balance
. Don't use it to invoke front-end routines, do that afterwards with something like:
if __name__ == "__main__":
ATM = Savingaccount()
ATM.menu()
If I were you I'd write at minimum class for the ATM that prompts the user and a class for the account that has a balance within it. My code would be something like:
class Account(object):
def __init__(self,acctholder,balance,pin):
self.acctholder = acctholder # name
self._balance = balance # amount as a decimal.Decimal
self.pin = pin # a hashed pin number
@staticmethod
def confirmPIN(pin, hash):
# hash a given PIN and check it against the hash
def deposit(self,amount):
self._balance += amount
def withdraw(self,amount,pin):
# hash the pin and check against self.pin
# if False, raise PermissionError
else:
self._balance -= amount
@property
def balance(self):
return self._balance
class ATM(object):
def __init__(self):
self.accounts = {#hash: <class Account>, ... }
def menu(self):
print("All the user options, and handle input and routing here")