Build a Budget App Project - Build a Budget App Project

Tell us what’s happening:

I cant get pass the create_spend_chart test, but couldnt figure out why

Your code so far

def create_spend_chart(categories):
    total = 0
    for i in categories:
        for _ in i.ledger:
            if _["amount"] < 0:
                total += -_["amount"]
    total_spent = sum(-item["amount"] for category in categories for item in category.ledger if item["amount"] < 0)
    spend_percentages = [
(sum(-_["amount"] for _ in i.ledger if _["amount"] < 0) / total) * 100 for i in categories
]
    chart_percentage = {category.category: spend_percentages[i] for i, category in enumerate(categories)}
    sorted_dict = {}
    for key in sorted(chart_percentage, key=chart_percentage.get):
        sorted_dict[key] = chart_percentage[key]
    chart ='Percentage spent by category\n'
    for i in range(100, -1, -10):
        chart += str(i).rjust(3)+'|'
        for _ in sorted_dict:
            if sorted_dict[_] >= i:
                chart += ' o '
            else:
                chart += '   '
        chart += '\n'
    chart += '    '
    for i in sorted_dict:
        chart += '---'
    chart += '-'
    chart += '\n'

    for _ in range(max(map(len, sorted_dict))):
        chart += '    '
        for i in sorted_dict:
            if _ < len(i):
                chart += f' {i[_]} '
            else:
                chart += '   '
        chart += '\n'
    return chart.rstrip('\n')

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0

Challenge Information:

Build a Budget App Project - Build a Budget App Project

Press F12 to open the browser console. You’ll see more details about the failing tests. If you still need help, please post the entire code.