Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJack Cummins
17,417 PointsHow come I get an error message?
My code is:
class Bank:
def __init__(self):
self.balance = 0
def deposit(self, mon):
self.balance += mon
return self.balance
def withdraw(self, mon):
self.balance -= mon
return self.balance
def balance(self):
return self.balance
def take_out_all(self):
if self.balance > 0:
self.balance -= self.balance
return self.balance
else:
return "You can only take out all of your money if you have a POSITIVE amount of money"
def deposit_100(self):
self.balance += 100
return self.balance
def withdraw_100(self):
self.balance -= 100
return self.balance
But when I use Bank.balance(), I get an error that says:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
1 Answer
Steven Parker
229,204 PointsI see a couple of issues here. First, you have a property named "balance" where you store a value, but then you also have a method with that same name. When you create a new instance, the method gets overwritten by the property. To avoid such confusion, always give methods and properties different names.
Also, since "Bank" is the class name, it would not be a good name for an instance. And if it's not an instance, "Bank.balance()
" would not be valid because it's not a class method.