首页 > 解决方案 > NoneType 对象没有属性

问题描述

def 预测(银行,年份):

类银行:

def __init__(self, name):
    self.name = name
    self.mark_cap = 0
    self.acc_list = []
    self.age = 0

def lend(self, principal, ann_inc):
    self.mark_cap -= principal

def forward_year(self):
    self.age += 1

def back_year(self):
    if self.age == 0:
        self.age = 0
    self.age -= 1

def show_high(self):
    print(Bank.acc_list[0])

班级帐号:

def __init__(self, ID, password):
    self.ID = ID
    self.password = password
    if len(password) < 5:
        print('Password must be at least 5 characters')
    self.amount = 0
    self.interest = 0.0175
    self.acc_org = [ID, password, self.amount, self.interest]

def deposit(self, x):
    self.amount += x
    self.acc_org[2] = self.amount

def withdraw(self, y):
    self.amount -= y
    self.acc_org[2] = self.amount

def threshold(self):
    if self.amount >= 1000000:
        self.interest = 0.02

def comp_int(self, n):
    self.threshold()
    self.amount *= (1 + self.interest)**n
    self.acc_org[2] = self.amount

def show_amount(self):
    print(self.amount)

def add_2_bank(self, name):
    bank_name = name
    bank_name.acc_list.append(self.acc_org)

X = Bank('中国银行')

Account1 = Account('12345', '12345') Account1.deposit(200) Account1.comp_int(2) Account1.add_2_bank(X)

X.show_high()

我得到的错误是我的“银行”对象(X)没有属性 acc_list()。有人请帮助我。

标签: pythonfunctionclassattributesbank

解决方案


show_high方法中,修改Bank.acc_listself.acc_list。只能使用静态属性,例如Bank.*.


推荐阅读