Problem with Python Budget app - test_create_spend_chart

Please could you help me, this is the only test the app is failing, as far as I can tell everything seems fine, but I got it wrong

Your code so far
This is the get_balance function

  def get_balance(self):
    accum = 0
    for sum in self.ledger:
      accum = sum["amount"] + accum
    return accum

This is the main function

def create_spend_chart(categories):
  string = "Percentage spent by category\n"
  accum = 0
  parts = []
  for category in categories:
    accum = accum + category.get_balance()
  for category in categories:
    parts.append(category.get_balance() * 100 / accum)
    
  act = 100
  while act >= 0:
    if act == 100:
      string = string + str(act) +"|"
    elif act > 0:
      string = string + " " + str(act) +"|"
    else:
      string = string + "  " + str(act) +"|"
    for part in parts:
      if part >= act:
        
        string = string + " o "
    act = act - 10
    string = string + "\n"
  string = string + "    -" + ("---"* len(parts)) + "\n"
  atoms = []
  for category in categories:
    atoms.append(list(category.category))
  atomicity = atoms.copy()
  while len(atomicity) > 0:
    subString = ""
    for atom in atoms:
      subString = subString + " " + atom[0] + " "
      if len(atom) >= 1 and atom[0]!=" ":
        atom.remove(atom[0])
        if len(atom) == 0:
          atom.append(" ")
          atomicity.remove(atomicity[0])
    if(len(atomicity) > 0):
      subString = subString + "\n"
    string = string + "    " + subString
  
  return string

Your browser information:

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

Challenge: Budget App

Link to the challenge:

1 Like

hi. try to study the correct spacing from the result provided by the test_module.py and compare this to your print out (the one below): you have 2 extra ’ o 's on line 30.

Blockquprint



good luck and have a good day!

3 Likes