У объекта клиента нет атрибутов аккаунта - PullRequest
0 голосов
/ 05 февраля 2020

Когда я запускаю приведенный ниже код, я получаю сообщение об ошибке:

У объекта Customer нет атрибутов account

Это происходит в функции createAccount в строке :

if type in customer.accounts:
        account=customer.accounts[type]

Я не уверен, как решить эту проблему.

class Bank:

    def __init__(self,name,code,address):
        self._name=name
        self._code=code
        self._address=address
        self._atms=[]
        self._customers={}

    def getName(self):
        return self._name

    def getCode(self):
        return self._code

    def getAddress(self):
        return self._address

    def createCheckingAccountNewCustomer(self,customerName,dateOfBirth,address):
        return self._createAccountNewCustomer(bank=self,type="checking",customerName=customerName,dateOfBirth=dateOfBirth,address=address)

    def createSavingsAccountNewCustomer(self,customerName,dateOfBirth,address):
        return self._createAccount(self,"savings",customerName,dateOfBirth,address)

    def createCheckingAccount(self,customer):
        return self._createAccount(bank=self,type="checking",customer=customer)

    def createSavingsAccount(self,customer):
        return self._createAccount(self,type="savings",customer=customer)

    def _createAccountNewCustomer(self,bank,type,customerName,dateOfBirth,address):
        #does this customer exist?
        customer=None
        if customerName.lower() in self._customers.keys():
            customer=self._customers[customerName.lower()]
        else:
            customer=Customer(customerName,dateOfBirth,address)
            self._customers[customerName.lower()]=customer

        return self._createAccount(bank,type,customer)

    def _createAccount(self,bank,type,customer):
        """Creates an account based on the information returned. Returns the account object."""

        #do we have an account for this customer?
        account=None

        if type in customer.accounts:
            account=customer.accounts[type]

        if account==None:
            if type=="checking":
                account = SavingsAccount(self,0,customer)
            else:
                account = CheckingAccount(self,0,customer)
            customer.accounts.append(account)
        return account

    def createATM(self,location):
        atm = ATMInfo(location,self)
        self._atms.append(atm)
        return atm

    def countAccounts(self):
        """goes through all customers and counts the total accounts"""
        count=0
        for x in self._customers.values():
            count += len(x._accounts)
        return count

    def __str__(self):
        result = "\n-----------Bank Details------------------\nBank:{}  Location:{}".format(self.getName(),self.getAddress())
        result+='\nTotal Customers='+str(len(self._customers))+'\n'
        for t in self._customers.values():
            result += str(t)

        result+='\n-----------End Bank Details------------'
        return result

class Customer:
    def __init__(self,bank,type,customer):
        self.bank =bank
        self.type=type
        self.customer=customer

    def createAccount(self,type,balance):
        self.type = type
        self.balance = balance


class DebitCard:
    def __init__(self,number,owner):
        self.owner=owner
        self.number=number


b = Bank("Lone Peak Bank", "Bank Number","Address")

checkingAccount = b.createCheckingAccountNewCustomer("Name","1/1/2020","Address")

savingAccount = b.createSavingsAccount(acct._owner)

atm = b.createATM("Lone peak ATM")

print(b)
print(atm)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...