Need help in finding problem with this code

Hello there
I am trying create a inheritance class for bank_account. The final balance should return the remaining amount. But, instead it returned “TypeError: charges() missing 2 required positional arguments: ‘bank_name’ and 'account_type”
I understand, there is a problem in charges function and I am not sure where I committed mistake. Can anyone help me?

# Creating inheritance in class
class bank_account:
    def __init__(self, deposit_amount, withdrawl_amount):
        self.deposit_amount = deposit_amount
        self.withdrawl_amount = withdrawl_amount
        self.balance = 1000
    def deposit(self):
        if self.deposit_amount != 0:
            return self.deposit_amount
        else:
            return self.balance
        
    def withdrawl(self):
        if self.withdrawl_amount != 0:
            return self.withdrawl_amount
        else:
            return self.balance

class withdrawl_charges(bank_account):
    def __init__(self, deposit_amount, withdrawl_amount):
        bank_account.__init__(self, deposit_amount, withdrawl_amount)
        self.bank_name = ["HDFC", "IDBI", "INDIAN BANK", "IOB", "AXIS BANK", "SBI"]
        self.account_type = ["Savings", "Current", "Buiness account"]
        self.remaining_balance = 0
        
    def charges (self, bank_name, account_type):
        if bank_name == self.bank_name[0] and account_type == self.account_type[0]:
            return self.withdrawl_amount * 0.005
        if bank_name == self.bank_name[0] and account_type == self.account_type[1]:
            return self.withdrawl_amount * 0.010
        if bank_name == self.bank_name[0] and account_type == self.account_type[2]:
            return self.withdrawl_amount * 0.015
        
        if bank_name == self.bank_name[1] and account_type == self.account_type[0]:
            return self.withdrawl_amount * 0.004
        if bank_name == self.bank_name[1] and account_type == self.account_type[1]:
            return self.withdrawl_amount * 0.09
        if bank_name == self.bank_name[1] and account_type == self.account_type[2]:
            return self.withdrawl_amount * 0.012
        
        if bank_name == self.bank_name[2] and account_type == self.account_type[0]:
            return self.withdrawl_amount * 0.002
        if bank_name == self.bank_name[2] and account_type == self.account_type[1]:
            return self.withdrawl_amount * 0.08
        if bank_name == self.bank_name[2] and account_type == self.account_type[2]:
            return self.withdrawl_amount * 0.010
        
        if bank_name == self.bank_name[3] and account_type == self.account_type[0]:
            return self.withdrawl_amount * 0.003
        if bank_name == self.bank_name[3] and account_type == self.account_type[1]:
            return self.withdrawl_amount * 0.06
        if bank_name == self.bank_name[3] and account_type == self.account_type[2]:
            return self.withdrawl_amount * 0.09
        
        if bank_name == self.bank_name[4] and account_type == self.account_type[0]:
            return self.withdrawl_amount * 0.006
        if bank_name == self.bank_name[4] and account_type == self.account_type[1]:
            return self.withdrawl_amount * 0.012
        if bank_name == self.bank_name[4] and account_type == self.account_type[2]:
            return self.withdrawl_amount * 0.017
        
        if bank_name == self.bank_name[5] and account_type == self.account_type[0]:
            return self.withdrawl_amount * 0.002
        if bank_name == self.bank_name[5] and account_type == self.account_type[1]:
            return self.withdrawl_amount * 0.07
        if bank_name == self.bank_name[5] and account_type == self.account_type[2]:
            return self.withdrawl_amount * 0.010
    def final_balance(self):
        self.remaining_balance += self.balance
        self.remaining_balance -= self.withdrawl ()
        self.remaining_balance -self.charges()
        self.remaining_balance += self.deposit()
        return self.remaining_balance
        
sam = withdrawl_charges(1000, 500)
sam.charges("IDBI", "Savings")
sam.final_balance()

the error message includes a line number? Its this one:

self.remaining_balance -self.charges()

you call the charges method, looking at method declaration/definition:

def charges (self, bank_name, account_type):

i can see 2 positional parameters (bank_name and account_type), but no arguments at the method call

not sure what is required here, for that i would need the exercise url, but hopefully this helps

1 Like