Build a Budget App - Build a Budget App

Tell us what’s happening:

I am having an issue in the Python curriculum where whenever I try during a workshop or lab to use sep=, end=, or, in some circumstances, ANSI escape codes, [object, Object] is printed. For example, should I attempt the following, this is what will happen:

print(“Spherical”, “Bee”, sep=“”) #Output: Spherical Toast [object, Object]

I am unsure what the problem may be or how to solve it, nor have I found anything addressing it. Any help is appreciated.

Your code so far

class Category:
  
  def __init__(self, name):
    self.name = name
    self.ledger = []
  
  def deposit(self, amount, description=""):
    self.ledger.append({"amount" : amount, "description" : description})
  
  def get_balance(self):
    balance = 0
    for index, transaction in enumerate(self.ledger):
      balance += self.ledger[index]["amount"]
    return balance
    
  def check_funds(self, amount):
    if amount > self.get_balance():
      return False
    else:
      return True
  
  def withdraw(self, amount, description=""):
    if self.check_funds(amount):
      self.ledger.append({"amount" : -amount, "description": description})
      return True
    else:
      return False
      
  def transfer(self, amount, other_instance):
    if self.check_funds(amount):
      self.withdraw(amount, f"Transfer to {other_instance.name}")
      other_instance.deposit(amount, f"Transfer from {self.name}")
      return True
    else:
      return False
      
  def __str__(self):
    print("*" * int((30 - len(self.name))/2), self.name, "*" * 
    (30 - (len(self.name) + int((30 - len(self.name))/2))), sep="")
    
    for index, entry in enumerate(self.ledger):
      description = ""
      amount = "{:.2f}".format(self.ledger[index]["amount"])
      if len(self.ledger[index]["description"]) >= 23:
        description = self.ledger[index]["description"][:23]
      else:
        description = self.ledger[index]["description"]
      
      if self.ledger[index]["amount"] >=7:
        amount = amount[-7:]
      else:
        pass
      
      print(description, " " * (30 - (len(description) + len(amount))), amount, sep="")
    return f"Total: {self.get_balance()}"
    
    
def create_spend_chart(categories):
  print("Percentage spent by category")
  index = 100 
  while index > 0:
    print(f"{index}|\n\033[1C ", end="")
    index = index - 10
    
    
    

    
food = Category("Food")
clothing = Category("Clothing")
auto = Category("Auto")
rent = Category("Rent")


food.deposit(1000, "initial deposit")
food.withdraw(10.15, "groceries")
food.withdraw(15.89, "restaurant and more food for dessert")
food.transfer(50, clothing)
print(food)


clothing.withdraw(30, "socks")
auto.withdraw(20, "seat cushions")
rent = (400, "monthly rent")

category_list = [food, clothing, auto, rent]

create_spend_chart(category_list)


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0

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

To clarify because my post makes it unclear, this issue is not specific to the Build a Budget App assignment; it’s just where this issue has caused me the most grief, hence why I ask it here.
Also, if my question is in any way not in line with forum guidelines, I apologize in advance.

Welcome to the forum @thhhhsn9

What is end="" for?

Happy coding

Every tick on the y-axis of the chart, save for the first one (“100|”), needs to be one space to the right in order to match the template given in the instructions. To that end, I used “\n\033[1C”, which moves the cursor down one and to the right, then used end=“” in order to prevent Python from automatically inserting what would be an extra, unwanted line.

Hi @thhhhsn9

The ANSI escape code is outputting:

[object, Object]

You’ll may need to use just a space to prevent the current output. Then remove the extra space at the end in another way.

Happy coding

not all features of print are supported

are you sure that you need to print to pass the tests?