2014-05-10 3 views
0

비슷한 질문을 보았지만 아직 이해할 수 없었습니다. 나는 어딘가에서 아주 어리석은 실수를하고 있다는 것을 확신하지만 나는 그것을 찾지 못하는 것 같습니다.왜 내가 TypeError를 얻는 지 혼란스러워합니다. 'int'객체를 호출 할 수 없습니다.

이 코드의 경우.

class BankAccount: 
    def __init__(self, initial_balance): 
     self.balance = initial_balance 

    def deposit(self, amount): 
     self.deposit = amount 
     self.balance = self.balance + self.deposit 

    def withdraw(self, amount): 
     self.withdraw = amount 
     self.balance = self.balance - self.withdraw 
     self.fee = 5 
     self.total_fees = 0 

     if self.balance < 0: 
      self.balance = self.balance - self.fee 
      self.total_fees += self.fee 

    def get_balance(self): 
     current_balance = self.balance 
     return current_balance 

    def get_fees(self): 
     return self.total_fees 

는 내가 추가 호출이이 오류가 발생합니다

my_account = BankAccount(10) 
my_account.withdraw(15) 
my_account.withdraw(15) 
my_account.deposit(20) 
print my_account.get_balance(), my_account.get_fees() 

철회 할 경우 나, 그러나이

my_account = BankAccount(10) 
my_account.withdraw(15) 
my_account.deposit(20) 
print my_account.get_balance(), my_account.get_fees() 

를 실행할 때 코드 모든 것이 잘 작동 실행하면.

TypeError: 'int' object is not callable

퇴장 전화를 추가로 신청해야만 정상적으로 작동하는 이유를 알 수 없습니다. 도와주세요.

답변

4

self.deposit = amount을 입력하면 deposit 메서드를 해당 금액으로 덮어 씁니다. withdraw에서 self.withdraw = amount으로 동일하게 수행합니다. 데이터 속성에 메서드와 다른 이름을 부여해야합니다 (예 : withdraw 메서드를 호출하고 속성은 withdrawalAmount 또는 그와 비슷한 것).

4

당신이 withdraw 방법

self.withdraw = amount 

안에이 작업을 수행 할 때 당신이 amount 무엇이든로 교체하십시오. 다음 번에 withdraw으로 전화하면 amount 개체가 생깁니다. 어떤 경우 귀하의 경우 int입니다.

동일 deposit에 적용

self.deposit = amount 

당신의 방법에 다른 데이터 멤버 이름을 지정합니다.

관련 문제