Budget app: Mysterious "type error"

Hi, when I test my budget app program, I get the following error:
TypeError: deposit() takes from 1 to 2 positional arguments but 3 were given

The error is associated with line 7 in the main.py file, but that line only gives two arguments when calling the deposit method.

Here’s my code (which admittedly doesn’t have either of the print-related tasks completed yet):

class Category:
    def __init__(self, category_name):
        self.name = category_name
        self.ledger = []
    
    def __str__(self):
        output_str = ''
        return output_str
    
    def deposit(amount, description=''):
        self.ledger.append({"amount": amount, "description":description})

    def withdraw(amount, description=''):
        if check_funds(amount):
            self.ledger.append({"amount": amount * -1, "description":description})
            return True
        else:
            return False

    def get_balance():
        balance = 0
        for entry in self.ledger:
            balance += entry["amount"]
        return balance

    def transfer(amount, other_cat):
        if self.check_funds(amount):
            self.withdraw(amount, "Transfer to " + other_cat)
            other_cat.deposit(amount, "Transfer from " + self.name)
            return True
        else:
            return False
    
    def check_funds(amount):
        if amount > self.get_balance():
            return False
        else:
            return True

def create_spend_chart(categories):
    pass

Every instance method needs to have self as the first parameter. Your __init__() and __str__() methods have it, but the rest are missing it.

1 Like

Ah, thanks, I see that now!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.