Budget App Fail

Tell us what’s happening:
I have compared my output to what is expected in the test_module.py, counting white space and all but for the life of me I can not figure out why I am getting these two failures:

Your code so far

class Category:
  def __init__(self, name):
    self.name = name
    self.amount = 0
    self.ledger= []
  #A deposit method for amount and description and add them to the ledger
  def deposit(self, amount, description=""):
    self.ledger.append({"amount": amount, "description": description})
    self.amount += amount
  #A withdrawl method for amount, as negative and checking to see if there are enough funds
  def withdraw(self, amount, description=""):
    if self.check_funds(amount) is False:
      return False
      self.amount -= amount
      self.ledger.append({"amount": amount*-1, "description": description})
      return True
  def get_balance(self):
    return self.amount
  def transfer(self,amount,category):
    if self.check_funds(amount):
      self.amount -= amount
      self.ledger.append({"amount": amount*-1, "description":"Transfer to " + category.name})
      category.ledger.append({"amount": amount,"description": "Transfer from "+self.name})
      return True
      return False
  def check_funds(self,amount):
    totinacct = self.get_balance()
    if amount > totinacct:
      return False
      return True
  def __str__(self):
    title = self.name.center(40, "*") + "\n"
    items = ""
    total = self.get_balance()
    for i in range(len(self.ledger)):
      items +=  f"{self.ledger[i]['description'][0:23]:23}" + f"{self.ledger[i]['amount']:>7.2f}" + "\n"
    output = title + items + "Total: " + str(total)

def create_spend_chart(categories):
  cats = [x]
  spending = []
  x = 0
  for each in categories:
    x = max(x, len(each.name))
    for item in each.ledger:
      spent = 0
      if item["amount"] < 0:
        spent += int(item["amount"])
  totalspent = sum(spending)
  for each in spending:
    spending[spending.index(each)] = int((each / totalspent) * 10) * 10
  output = "Percentage spent by category\n"
  for i in range(100, -10, -10):
    output += str(i).rjust(3, " ") + "|"
    for each in spending:
      if each >= i:
        output += " o "
        output += "   "
    output += " \n"
  numdashes = 3*len(cats)
  output += 4*" " + numdashes*"-" + "-\n"
  for i in range(x):
    output += 4*" "
    for each in categories:
      if i < len(each.name):
        output += " " + each.name[i] + " "
        output += 3*" "
    if i < x-1:
      output += " \n"

Your browser information:

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

Challenge: Budget App

Link to the challenge:

First thing that comes to my mind that you may have missed some spaces. Because the error clearly specifies that it expects 93 chars after \n deposit but your output only has 83 characters. Try to debug this and check for some mistakes in those spacings.

1 Like

Ahh I missed that. Thank you! I’ll go see what I can uncover.

1 Like

So yeah, don’t I feel stupid for not looking at the title. I must have typoed 40 when it should have been 30. Now on to the chart itself and why its not coming out as intended.

1 Like