Python Budget App: test_create_spend_chart fail

Tell us what’s happening:
For some reason, the categories that my chart prints are [Food, Clothing, Auto] instead of what it should print [Business, Food, Entertainment]. I’m not sure if this is because creates a chart for [Food, Clothing, Auto] or if there’s something wrong with my code. I tried to test the code (printed the list of categories multiple times throughout) and it’s always correct until I run the entire thing. Not sure what’s wrong…

Your code so far

def create_spend_chart(categories):
  cates = []
  spending = []
  spent = 0
  #Creates a list of category names + spending per category
  for category in categories:
    for item in category.ledger:
      spent = 0
      if item["amount"] < 0:
        spent += int(item["amount"])
  total = sum(spending)
  #Changes amounts in spending to percents
  for num in spending:
    spending[spending.index(num)] = int((num / total) * 10) * 10
  #Length of longest string in cates
  longest = len(max(cates, key=len))  
  #Starts putting together output strings
  title = "Percentage spent by category" + "\n"
  #Sets length of each category to max
  for cate in cates:
    cates[cates.index(cate)] = cate.ljust(longest)
  #Prints all categories in a vertical line
  cateString = "     "
  for i in range(0, longest):
    for cate in cates:
      cateString += cate[i] + "  " #Two spaces between each category
    cateString += "\n     " #Categories start 5 spaces away from edge
  graph = ""
  for i in range(100, -10, -10):
    bar = " "
    line = str(i).rjust(3) + "|"
    #Add o if percent spending reaches there, spaces otherwise
    for percent in spending:
      if percent >= i:
        bar += "o  "
        bar += "   "
    line += bar
    graph += line + "\n"
    dashes = "    " + (len(cates) * 3) * "-" + "-" +  "\n"
    output = title + graph + dashes + cateString

Your browser information:

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

Challenge: Budget App

Link to the challenge:

When run creates chart with [Food, Clothing, Auto], which is printed out. Later tests are run, which includes [Business, Food, Entertainment] as categories. Chart from these tests isn’t printed out, that’s all normal. Are you getting some error or just was confused with this behavior?

When I run the program, the last test fails. This is the error I get:

The part that shows what exactly differs from the expected result and actual function output is cut on the screen… My guess is that there’s somewhere one space too many or not enough. It might be easier if you paste full output with error, or just link to your code on

Sorry about that, I updated the picture.