Build a Budget App - Build a Budget App

Tell us what’s happening:

I cannot run or check my code. The code editor keep prompting “Your code raised an error before any tests could run. Please fix it and try again.”
The issue happened even I simply declare an class e.g.

class Category:
 ____pass

I try other previous exercises and it remains the same :frowning:

Your code so far

class Category:
    def __init__(self, category_name):
        self.category_name = category_name
        self.ledger = []

    def deposit(self, amount, description=''):
        self.ledger.append({'amount': amount, 'description': description})

    def withdraw(self, amount, description=''):
        canWithdraw = self.check_funds(amount=amount)
        
        if canWithdraw:
            self.ledger.append({'amount': - amount, 'description': description})
            return True
        else:
            return False
    
    def get_balance(self):
        balance = 0
        
        for transaction in self.ledger:
            balance += transaction['amount']
        
        return balance
    
    def transfer(self, amount, destination):
        canTransfer = self.check_funds(amount=amount)
        
        if canTransfer:
            self.withdraw(amount, f'Transfer to {destination.category_name}')
            destination.deposit(amount, f'Transfer from {self.category_name}')
            return True
        else:
            return False
        
    def check_funds(self, amount: int):
        balance = 0
        for transaction in self.ledger:
            balance += transaction['amount']

        if amount < balance:
            return True
        else:
            return False
        
    def __str__(self):
        balance = 0
        print(self.category_name.center(31, '*'))
        for transaction in self.ledger:
            balance += transaction['amount']
            clean_desc = transaction['description'][:23]
            print(f'{clean_desc:<23} {transaction['amount']:>7.2f}')
        print(f'Total: {balance:.2f}')

def create_spend_chart(categories):
    print('Percentage spent by category')

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0

Challenge Information:

Build a Budget App - Build a Budget App

Welcome to the forum @tinit!

Try fixing the syntax error showing in the console:

Traceback (most recent call last):
File “main.py”, line 52
print(f’{clean_desc:<23} {transaction[‘amount’]:>7.2f}')
^^^^^^
SyntaxError: f-string: unmatched ‘[’

Happy coding!