菜鸟学习python习题 class子类遇错误 上面原因呢?

class BankAccount:
def __init__(self,name,bid,balance):
self.bank_name=name
self.bank_bid=bid
self.bank_balance=balance

def __str__(self):
msg="用户名:"+self.bank_name+" "+"ID"+self.bank_bid+" "+"余额"+self.bank_balance
return msg
class InterestAccount(BankAccount):
def __init__(self,interest):
BankAccount.__init__(self)
self.interest=0.2

def newAccount(self):
for i in range(366):
if i%365==0:
myAccount.bank_balance=myAccount.bank_balance+myAccount.bank_balance*0.2
return myAccount.bank_balance

myAccount=BankAccount("a","111111112","999")
print(myAccount)
myAccount.newAccount()
print(myAccount)

》》》》
用户名:a ID111111112 余额999
Traceback (most recent call last):
File "/Volumes/Untitled 2/Personal/Python/StudyPY.py", line 23, in <module>
myAccount.newAccount()
AttributeError: 'BankAccount' object has no attribute 'newAccount'

newAccount是子类InterestAccount才有的方法myAccount是基类BankAccount实例,BankAccount没有newAccount方法.追问

请问如何调用子类中的方法呢?

温馨提示:答案为网友推荐,仅供参考
相似回答