Search code examples
pythontypeerror

BankSystem and I want to take loan but it throws a TypeError


I've tried to make a take loan from BankSystem but it throws an error and says list object is not callable, i want to ask the user to enter the price between 100 euros and 300euros and if that number be higher that is not accept but if that sum is from 100euros and 300 euros it is accepted:

import datetime
class BankSystem:
    total_deposit = 0
    total_withdraw = 0
    def __init__(self,name,accountNumber,salary):
        self.name = name
        self.accountNumber = accountNumber
        self.salary = salary
        self.withdraw_history = []
        self.deposit_history = []
        self.take_loan = []
    def description(self):
        print("Name is: " , self.name)
        print("AccountNumber: " , self.accountNumber)
        print("Salary: " , self.salary)
    def deposit(self,deposit):
        self.salary = self.salary + deposit 
        self.deposit_history.append(deposit)
        self.total_deposit += 1
    def withdraw(self,withdraw):
        self.salary = self.salary - withdraw
        self.withdraw_history.append(deposit)
        self.total_withdraw += 1
    def transaction_history(self):
        print("You have withdraw", self.withdraw_history , "On date:" , datetime.datetime.now())
        print("You have deposit" , self.deposit_history , "On date:" , datetime.datetime.now())
    def take_loan(self):
        answer = int(input("Enter the amount of loan who would you like to take between - 100Euros and 300 Euros: "))
        if answer > 300:
            print("Choose between 100 - 300 Euros not more")
        else:
            print("You have taken out for loan" , answer)
            self.take_loan.append(answer)
            
        
bank = BankSystem("Bill" , 42919502 , 4000)
bank.take_loan()   

Solution

  • Remove the line self.take_loan = [].

    You're overriding the take_loan() function with an empty list object, then trying to call it.