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'
请问如何调用子类中的方法呢?