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

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

QA

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

본문

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)
<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를 호출할 때 파라미터를 적어 주셔야 합니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 208
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT