Python Error: List Object Not Callable with For Loop -


alright i'm having typeerror: 'list' object not callable

it's on loop below (if type=='d')

exact error follows:

     traceback(most recent call last):      file"test.py", line 55 in <module>      main()      file "test.py", line 49, in main      in range(len(accountlist())):      typeerror: 'list' object not callable 

my code below, i've tried putting each parenthesis in brackets , renaming list different, getting around same error.

what doing wrong here?

class bankaccount:  def __init__(self, getbankaccount, inputamount=0):      self.__balance = inputamount      self.__numdeposits = 0      self.__numwithdrawals = 0      self.__totaldeposits = 0      self.__totalwithdrawals = 0      self.__getbankaccount=getbankaccount  def getbalance(self):      return self.__balance  def getnumdeposits(self):      return self.__numdeposits  def getnumwithdrawals(self):      return self.__numwithdrawals  def gettotaldeposits(self):      return self.__totaldeposits  def gettotalwithdrawals(self):      return self.__totalwithdrawals  def getbankaccount(self):      return self.__getbankaccount  def deposit(self,amount):      self.__balance = self.__balance + amount      self.__numdeposits = self.__numdeposits + 1      self.__totaldeposits = self.__totaldeposits + amount      return self.__balance  def withdrawal(self,amount):      if (self.__balance >= amount):          self.__balance = self.__balance - amount          self.__numwithdrawals = self.__numwithdrawals + 1          self.__totalwithdrawals = self.__totalwithdrawals + amount          return true      else:          return false   def main(): accountlist=[]  numbers=eval(input())  in range(numbers):      account=input()      amount=eval(input())      initial=bankaccount(account, amount)      accountlist.append(initial)      type=input()      while type!='#':          if type=='d':              account=input()              amount=eval(input())              in range(len(accountlist())):                  if(account==accountlist[i].getbankaccount()):                      index=i                      accountlist[index].deposit(amount)                      print(amount, type, account)          type=input() main() 

your problem in line for in range(len(accountlist())): have accountlist(). accountlist list, , () means you're trying call function. change line for in range(len(accountlist)): , should set.

on sidenote, it's easy recognize problem error:

 typeerror: 'list' object not callable 

is telling need know: you're trying "call" list on line 49. learning read error messages important , useful skill.


Comments