테스트 사이트 - 개발 중인 베타 버전입니다

안녕하세요. 코린이 파이썬 질문드려요ㅜㅜ

JH120 4년 전 조회 1,956

class 상속 문제인데 마지막에 이율 0.08을 계산하여 총 잔액을 나타내려고 하는데 계속 오류가 뜨네요.. 어떻게 해야할까요.....

 

---------------------------------------------------------------------------------------------------------

 

class BankAccount:

  def __init__(self, ac_name, ac_num, ac_bal):

    self.ac_name = ac_name

    self.ac_num = ac_num

    self.ac_bal = ac_bal

    

  def displayBal(self):

    print("잔액은 %d"% self.ac_bal)

 

  def deposit(self, money):

    self.ac_bal += money

    print("%d 입금, 잔액은 %d."%(money, self.ac_bal))

 

  def withdraw(self, money):

    if self.ac_bal >= money:

      self.ac_bal -= money

      print("%d 출금, 잔액은 %d."%(money, self.ac_bal))

    else:

      print("잔액 부족")       

 

class Interest:

  def __init__(self, ac_name, ac_num, ac_bal, addInterest):

    BankAccount.__init__(self, ac_name, ac_num, ac_bal)

    self.addInterest = addInterest

      

  def addInterest(self,money):

    self.ac_bal += (money*0.08)

    print("이자 계산 후 잔액은 %d."%(money, self.ac_bal))

   
 

myAccount = BankAccount("JENY","1234",10000) 

myAccount.displayBal()

myAccount.deposit(10000)

myAccount.withdraw(100000)

myAccount.withdraw(5000)

Interest.addInterest()

--------------------------------------------------------------------------------------------

잔액은 10000
10000 입금, 잔액은 20000.
잔액 부족
5000 출금, 잔액은 15000.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
https://localhost:8080/#"><ipython-input-89-42a5ae7d8fad> in <module>()
     36 myAccount.withdraw(100000)
     37 myAccount.withdraw(5000)
---> 38 Interest.addInterest()
     39 
     40 

TypeError: addInterest() missing 2 required positional arguments: 'self' and 'money'

 

 

라고 오류가 나옵니다...

앞의 예시 결과 15000 이후에 이율 0.08을 계산해 16200원이라는 잔액이 마지막에 나오게 하고 싶은데

대체 무엇이 문제이고 어떻게 수정해야할까요 선생님들 ㅠㅠㅠㅠ 

 

 

 

 

 

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

def addInterest(self,money):

이렇게 정의하고 있으니

addInterest를 호출할 때 파라미터를 적어 주셔야 합니다.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

J
JH120
4년 전
답변 감사합니다! 그런데 self, money 자리에 대체 무슨 값을 넣어야할지도 모르겠어요??

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인