Help me with the code

My code]

class Category:
    def __init__(self, name):
        self.name = name
        self.ledger = []
        
    def __str__(self):
        returnvalue = ""
        title = ("*" * 13)+self.name+("*"*13)
        titlelen = len(title)
        items = ""
        total = ""
        tamount = []
        tdesc = []
        totalamt = 0
        returnvalue += title
        returnvalue += "\n"
        for item in self.ledger:
            thamount = self.getamt(item)
            thdesc = self.getdesc(item)
            tamount.append(thamount)
            tdesc.append(thdesc)
        for i in range(len(tdesc)):
            newdesc = ""
            if tdesc[i] == "deposit":
                tdesc[i] = "initial deposit"
            if len(tdesc[i]) + len(tamount[i]) > titlelen:
                newlen = (len(tdesc[i])-(len(tdesc[i]) - titlelen)) - len(tamount[i]) - 1
                for j in range(newlen):
                    newdesc += tdesc[i][j]
                tdesc[i] = newdesc
            if "." not in tamount[i]:
                newtdesc = tamount[i] + ".00"
                tamount[i] = newtdesc
        for i in range(len(tdesc)):
            totalamt += float(tamount[i])
        #Add to items var
        for i in range(len(tamount)):
            items += tdesc[i]
            spaceform = titlelen - (len(tdesc[i])+len(tamount[i]))
            items += " " * (titlelen - (len(tdesc[i])+len(tamount[i])))
            items += tamount[i]
            items += "\n"
        returnvalue += items
        
        total = "Total: " + str(totalamt)
        returnvalue += total
        return returnvalue
    def getamt(self, dicts):
        newdicts = ""
        for i in str(dicts):
            digits = "1234567890.-"
            if i in digits:
                newdicts += i 
        return newdicts
    def getdesc(self, dicts):
        switch = 0
        switch2 = 0
        switch3 = 0
        switch4 = 0
        description = ""
        description2 = ""
        for i in str(dicts):
            if i == ",":
                switch = 1
            if switch == 1:
                if i == ":":
                    switch2 = 1
            if switch2 == 1:
                if i == " ":
                    switch3 = 1
            if switch3 == 1:
                if i == "'":
                    switch4 = 1
            if switch4 == 1:
                description += i
        for i in description:
            nochar = "'}"
            if i not in nochar:
                description2 += i
            
        return description2
    def deposit(self, amount, description = ""):
        self.ledger.append({"amount":amount,"description":description})
        return True
    def get_balance(self):
        return sum(item["amount"] for item in self.ledger)
    def check_funds(self, amount):
        return amount <= self.get_balance()
    def withdraw(self, amount, description = ""):
        if not self.check_funds(amount):
            return False
        self.ledger.append({"amount": -amount, "description": description})
        return True
    def transfer(self, amount, destination_category):
        if not self.check_funds(amount):
            return False
        self.ledger.append({"amount": -amount, "description": f"Transfer to {destination_category.name}"})
        destination_category.ledger.append({"amount": amount, "description": f"Transfer from {self.name}"})
        return True
    
def create_spend_chart(categories):
    pass

food = Category('Food')
food.deposit(1000, 'deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
print(food)

doesn’t complete step 16 despite print the page. I’m really confused why even though I followed the instructions. Can someone help me?

Hi @2012alexni

You created the Category class.

Now you need to fill out create_spend_chart function for the bar chart.

Happy coding

I’m saying that I need to first complete step 16. Even if I create the create_spend_chart function, the step 16 may still not be completed.

Here is a way to troubleshoot spacing / string issues. You’ll need to open the browser console.

The assertion error and diff gives you a lot of information to track down a problem. For example:

AssertionError: 'Year' != 'Years'
- Year
+ Years
?     +

Your output comes first, and the output that the test expects is second.

AssertionError: ‘Year’ != ‘Years’

Your output: Year does not equal what’s expected: Years

This is called a diff, and it shows you the differences between two files or blocks of code:

- Year
+ Years
?     +

- Dash indicates the incorrect output
+ Plus shows what it should be
? The Question mark line indicates the place of the character that’s different between the two lines. Here a + is placed under the missing s .

Here’s another example:

E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E       assert '  3801      123    \n   - 2     + 49    \n------    -----    \n' == '  3801      123\n-    2    +  49\n------    -----'
E         -   3801      123
E         +   3801      123    
E         ?                ++++
E         - -    2    +  49
E         +    - 2     + 49    
E         - ------    -----
E         + ------    -----    
E         ?                +++++

The first line is long, and it helps to view it as 2 lines in fixed width characters, so you can compare it character by character:

'  3801      123    \n   - 2     + 49    \n------    -----    \n'
'  3801      123\n-    2    +  49\n------    -----'

Again, your output is first and the expected output is second. Here it’s easy to see extra spaces or \n characters.

E         -   3801      123
E         +   3801      123    
E         ?                ++++

Here the ? line indicates 4 extra spaces at the end of a line using four + symbols. Spaces are a little difficult to see this way, so it’s useful to use both formats together.

I hope this helps interpret your error!

look in the browser console, you are not following all the requirements to build the string rapresentation

When you ask for help please do not forget to share a link to the project. In this case it is