Budget App Project - space problem with create_spend_chart function

hi! my create_spend_chart() function is failing the test because of the spaces, but I don’t seem to find the problem. I’d be grateful if you could help me find it, here’s the code:

def create_spend_chart(categories):
    output = ['Percentage spent by category']
    percentage = []
    category = []
    numbers = list(range(100,-1,-10))

    for budget in categories:
        total = sum([x['amount'] for x in budget.ledger if x['amount']>0])
        spent = sum([x['amount'] for x in budget.ledger if x['amount']<0])
        percentage.append(round((spent*-1)/total * 100))
        category.append(budget.name)
    
    for i in range(len(numbers)):
        output.append("{:3d}|".format(numbers[i]))
        for x in percentage:
            if x >= numbers[i]-5:
                check = 'o'
            else:
                check = ''
            output[i+1] += "{:^3}".format(check)

    output.append('    '+('-'*(3*len(category)+1)))
    longest = max(category,key=len)

    for i in range(len(longest)):
        output.append('    ')
        for j in range(len(category)):
            if len(category[j])> i:
                output[-1] += ' '+category[j][i]+' '
            else:
                output[-1] += '   '

    result = '\n'.join(output)
    return result

it also says the diff is 1232 characters long.

Please provide a link to your project so we can actually see the error message.

Your code had accuracy and spacing issues. I made some progress with it but couldn’t get it to work. Here is the modified code -

def create_spend_chart(categories):
  
   output = ['Percentage spent by category']
   percentage = []
   names = []
   numbers = list(range(100, -1, -10))
   spend = 0

   for budget in categories:
       names.append(budget.name)
       spend += budget.withdrawl

   for category in categories:
       percentage.append(((category.withdrawl / spend) * 100).__round__(-1))

   for i in range(len(numbers)):
       output.append("{:3d}|".format(numbers[i]))
       for x in range(len(percentage)):
           if x == 0:
               if percentage[x] >= numbers[i] - 5:
                   check = 'o'
               else:
                   check = ''
               output[i + 1] += "{:>2}".format(check)
           else:
               if percentage[x] >= numbers[i] - 5:
                   check = 'o'
                   output[i + 1] += "{:>3}".format(check)
               else:
                   output[i + 1] += "  "



   output.append('    ' + ('-' * (3 * len(names) + 1)))
   longest = max(names, key=len)

   for i in range(len(longest)):
       output.append('    ')
       for j in range(len(names)):
           if len(names[j]) > i:
               output[-1] += ' ' + names[j][i] + ' '
           else:
               output[-1] += '   '

   result = '   \n'.join(output)
   return result