0

Trying to deposit into the wallet, it worked the first call, then when I call the deposit function again it would give me the error.
TypeError: 'int' object is not callable Any solutions to this?

class Bank():

    def __init__(self,wallet):
        self.wallet = wallet

    def withdraw(self,withdraw):
        self.withdraw = withdraw

    def deposit(self, deposit):
        self.deposit = deposit
        self.wallet += self.deposit




bank = Bank(0)

bank.deposit(500)
print(bank.wallet)
bank.deposit(500)
print(bank.wallet)
4
  • 1
    Why did you do self.deposit = deposit? Once you've done that bank.deposit is not a method any more, it's an int. Commented Nov 22, 2021 at 22:24
  • I was assuming that each time I create a function in a class that I would need to the self. for each variable. Commented Nov 22, 2021 at 22:26
  • You see lines like that in __init__ methods frequently because __init__ is where you define all the attributes of an object, but you usually don't want to set new attributes outside of __init__, nor do all the attributes set in __init__ need to be 1:1 with the function arguments. For example, your Bank.__init__ could just always set self.wallet = 0 to start with and not require a wallet argument at all. Commented Nov 22, 2021 at 22:39
  • Ah, okay I'll keep a note of that, thank you very much for clarifying this! Commented Nov 22, 2021 at 22:43

1 Answer 1

2

You're reassigning your deposit function to an integer in the line. self.deposit = deposit. Remove that :)

Sign up to request clarification or add additional context in comments.

1 Comment

With the same logic, remove self.withdraw = withdraw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.