Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python OOP, how to keep adding a number Instance attribute?

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)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You’re reassigning your deposit function to an integer in the line. self.deposit = deposit. Remove that 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading