Budget app syntax problem

I seem to have a problem with the budget app, it always gives me this one specific syntax error

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

what error do you get?


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Oh thank you, didn’t know that.
Screenshot 2021-04-12 at 17.22.39
I get a syntax error and I’m not quite sure why

what does the syntax error say?

“code”: “syntax-error”,
“severity”: 8,
“message”: “invalid syntax (, line 30)”,

and what’s above it?

class Category:
    def __init__(self, name):
        self.name = name
        self.ledger = list()
    
    def __str__(self):
        title = f"{self.name: *^30}\n"
        items = ""
        total = 0
        for items in self.ledger:
            item +=f"{item['description'][0:23]:23}" + f"{item['amount']:>7.2f}" + "\n"

            total += item ["amount"]
        output= title + items + "Total: " + str(total)
        return output

    def deposit(self, amount, description=""):
        """A deposit method that accepts an amount and a description. 
        If no description is given, it should default to an empty string. 
        The method should append an object to the ledger list in the form 
        of {"amount" : amount, "description": description}
    """
    self.ledger.append({"amount": amount, "description": description}

aren’t you missing a )?

I just found it. Thank you

when there is a werid syntax error, always look what’s before it

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