Build a Budget App - Build a Budget App

Tell us what’s happening:

I can’t figure out what exactly is the problem with the final output.
There are four boxes that are still unchecked

Your code so far



def create_spend_chart(categories):
    title = "Percentage spent by category\n"
    spent = []
    percent = []
    strg = ""
    for i in categories:
        min_sum = 0
        for f in i.ledger:
            if f['amount'] < 0:
                min_sum += (f['amount']*-1)
        spent.append(min_sum)
    
    total_spent = sum(spent)

    for spending in spent:
        perc = (spending * 100)/total_spent
        percent.append(perc)
    
    for indx, val in enumerate(percent):
        if val % 10 != 0:
            rem = val % 10
            if rem < 5:
                percent[indx] = (val // 10) * 10
            if rem >= 5:
                new_val = (val // 10) + 1
                percent[indx] = new_val * 10
                
    for y in range(100, -1, -10):
        strg += (f"{y:>3}|")
        for k in (percent):
            if k >= y:
                strg += (f"{'o':^3}")
        strg += '\n'
    strg += (f"{'-':>5}")
    for _ in range(len(percent) * 3):
        strg += ("-") 
    strg += '\n'
    name = [cat.name for cat in categories]
    for i in range(len(max(name, key= lambda x:len(x)))):
        for indx, j in enumerate(name):
            pos = 6 if indx == 0 else 3
            try:
                strg += (f"{j[i]:>{pos}}")
            except IndexError:
                strg += (f"{'':>{pos}}")
                continue
        if i != (len(max(name, key= lambda x:len(x))) - 1):
            strg += '\n'

    return title + strg

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36

Challenge Information:

Build a Budget App - Build a Budget App

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-budget-app/5e44413e903586ffb414c94e.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @eermiale

To test out your function add the sample code:

food = Category('Food')
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
print(food)

Happy coding

Hi @eermiale,

If you need more help, please post ALL of your code, formatted as follows:

There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:

Happy coding

Tell us what’s happening:

This is a repost with the whole code. I have tested it, and output seems ok, but it still is not accepted

Your code so far

class Category:
def _init_(self, name):
self.name = name
self.ledger = []

def deposit(self, amnt, description = ""):
    self.ledger.append({'amount': amnt, 'description': description})
def withdraw(self, amnt, description = ""):
    lngth = len(self.ledger)
    if self.check_funds(amnt):
        self.ledger.append({'amount': -amnt, 'description': description})
        if len(self.ledger) == lngth + 1:
            return True
    else:
            return False
def get_balance(self):
    sum_amnt = 0

    for i in self.ledger:
        sum_amnt += i\['amount'\]
    return sum_amnt

def transfer(self, amnt, category):
    len_ordr = \[len(self.ledger), len(category.ledger)\]
    if self.check_funds(amnt):
        withdraw_desc = f"Transfer to {category.name}"
        deposit_desc = f"Transfer from {self.name}"
        
        self.withdraw(amnt, withdraw_desc)
        category.deposit(amnt, deposit_desc)

        if len(self.ledger) == len_ordr\[0\] + 1 and len(category.ledger) == len_ordr\[1\] + 1:
            return True
    else:
            return False
def check_funds(self, amnt):
    sum_amnt = self.get_balance()
    if amnt > sum_amnt:
        return False
    else:
        return True
def \__str_\_(self):
    sum_amnt = self.get_balance()
    ret_frm = f"{self.name:\*^30}\\n"
    for i in self.ledger:            
        ret_frm += f"{i\['description'\]:<23.23}"
        ret_frm += f"{i\['amount'\]:>7.2f}"
        ret_frm += "\\n"            

    ret_frm += f"Total: {sum_amnt:.2f}"
    return ret_frm
def create_spend_chart(categories):
  title = "Percentage spent by category\n"
  spent = []
  percent = []
  strg = ""
  for i in categories:
    min_sum = 0
   for f in i.ledger:
    if f['amount'] < 0:
    min_sum += (f['amount']*-1)
    spent.append(min_sum)
  total_spent = sum(spent)
  
  for spending in spent:
      perc = (spending \* 100)/total_spent
      percent.append(perc)

  for indx, val in enumerate(percent):
      if val % 10 != 0:
          rem = val % 10
          if rem < 5:
              percent\[indx\] = (val // 10) \* 10
          if rem >= 5:
              new_val = (val // 10) + 1
              percent\[indx\] = new_val \* 10
            
  for y in range(100, -1, -10):
      strg += (f"{y:>3}|")
      for k in (percent):
          if k >= y:
              strg += (f"{'o':^3}")
      strg += '\\n'
  strg += (f"{'-':>5}")
  for \_ in range(len(percent) \* 3):
      strg += ("-") 
  strg += '\\n'
  name = \[cat.name for cat in categories\]
  for i in range(len(max(name, key= lambda x:len(x)))):
      for indx, j in enumerate(name):
          pos = 6 if indx == 0 else 3
          try:
              strg += (f"{j\[i\]:>{pos}}")
          except IndexError:
              strg += (f"{'':>{pos}}")
              continue
      if i != (len(max(name, key= lambda x:len(x))) - 1):
          strg += '\\n'

  return title + strg
food = Category('Food')
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
print(food)
print(create_spend_chart([food, clothing]))

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36

Challenge Information:

Build a Budget App - Build a Budget App

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-budget-app/5e44413e903586ffb414c94e.md at main · freeCodeCamp/freeCodeCamp · GitHub

I went ahead and combined your posts for you. In the future, just reply to the original thread to add further updates.

Your code is still not formatted as asked. Please try that again following the instructions given above.

What tests are failing when you check your code?

Edit: Try this: in the fCC editor, enter Ctrl+A to select all of your code, then Ctrl+C to copy your code. Reply to this post or create a new post and enter 3 backticks (```). Position your cursor on the line under the backticks, then Ctrl+V to paste your code. At the end of your code, add 3 more backticks. If you do that, your code should be formatted so it can be tested.

Thank you.