【问题标题】:NoneType object has no attributeNoneType 对象没有属性
【发布时间】:2019-12-27 00:15:50
【问题描述】:

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()。有人请帮帮我。

【问题讨论】:

  • nameadd_2_bank 方法中为None

标签: python function class attributes bank


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-02
    • 2014-07-05
    • 2018-05-05
    • 2013-02-11
    • 2018-12-01
    • 2017-08-02
    • 2021-04-27
    • 2021-12-11
    相关资源
    最近更新 更多