Build a Budget App - Build a Budget App

Tell us what’s happening:

Hello, I am receiving errors indicating that I am not adding my objects to the ledger instance variable when I am. Why is this occurring? I assume this is occurring because I am modifying the description and amount. I am attaching the errors, and the printout screenshot seems to be what this lesson is asking for.

Thank you.

Your code so far

class Category:
    def __init__(self, name):
        self.name = name
        self.ledger = []
        self.balance = 0
    
    def deposit(self, amount, description = ""):
        self.balance += amount
        Test_printout = f'{description:<23.23} {amount:>7.2f}'
        self.ledger.append(Test_printout)
        return
    
    def withdraw(self, amount, description = ""):
            self.balance += -abs(amount)
            Amount_Deduction = -abs(amount)
            Test_printout = f'{description:<23.23} {Amount_Deduction:>7.2f}'
            self.ledger.append(Test_printout)
            if self.check_funds(amount):
                return True 
            else:
                return False
    def get_balance(self):
        return self.balance
    def transfer(self, amount, category):
        if self.check_funds(amount):
            self.withdraw(amount,f'Transfer to {category.name}')
            category.deposit(amount,f'Transfer from {self.name}')
            return True
        else: 
            return False
    def check_funds(self, amount):
        if amount > self.balance:
            return False
        else:
            return True
    
    def __str__(self):
        Balance = f"{self.balance:7.2f}"
        Balance_String = f'Total: {Balance}'
        Name = self.name.center(30, "*")
        result = f"{Name} \n"
        for list in self.ledger:
            result += (list) + "\n"
       
        return result + Balance_String
        
entertainment = Category('Entertainment')
food = Category('Food')
food.deposit(900, 'initial deposit')
food.withdraw(100.67, 'candy')
food.withdraw(45.67, 'milk, cereal, eggs, bacon, bread')
food.get_balance()
food.transfer(100, entertainment)
print(food)











Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 Edg/150.0.0.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

Let’s work on solving the first issue. You can see the milk, cereal,etc... entry. I believe an issue could be that the text is being cut-off. Do you know what is shrinking the length of the description?

The method should append an object to the ledger list in the form of {'amount': amount, 'description': description}.

Are you sure that the ledger is containing objects?

Hello, thank you for your response. Below is a screenshot of the portion that was wanting me to cut off the length of the description. I am under the impression that the .23 is cutting off the text which seems to be desired based on below.

Hello, thank you for the response. I overlooked that part earlier in the topic when I made alterations to it to fit below. It seems then that I must do below and have the above format when appending to the ledger list?

no, you need to append to the ledger list based on user story 3

Thank you for the response. I modified my code and I am passing those other tests but I am stuck at test 16: “Printing a Category instance should give a different string representation of the object.”

I assume this pertains to story 4 which I feel like I am doing correctly. Do you know what I am doing wrong?

class Category:
    def __init__(self, name):
        self.name = name
        self.ledger = []
        self.balance = 0
    
    def deposit(self, amount, description = ""):
        Test_deposit = {"amount": amount, "description": description}
        self.ledger.append(Test_deposit)
        self.balance += amount
        return
    
    def withdraw(self, amount, description = ""):
        Test_withdraw = {"amount": -abs(amount), "description": description}
        self.ledger.append(Test_withdraw)
        self.balance += -abs(amount)
        if self.check_funds(amount):
            return True 
        else:
            return False
    
    def get_balance(self):
        return self.balance
    
    def transfer(self, amount, category):
        if self.check_funds(amount):
            self.withdraw(amount,f'Transfer to {category.name}')
            category.deposit(amount,f'Transfer from {self.name}')
            return True
        else: 
            return False
    
    def check_funds(self, amount):
        if amount > self.balance:
            return False
        else:
            return True
    
    def __str__(self):
        Balance = f"{self.balance:7.2f}"
        Balance_String = f'Total: {Balance}'
        Name = self.name.center(30, "*")
        data = ''
        Dictionary = self.ledger
        for key in Dictionary: 
            description = key.get("description")
            amount = key.get("amount")
            amount_string = str(amount)
            line_item = description + amount_string +"\n"
            line_item_2 = f"{description:<23.23} {amount:>7.2f}\n"
            data += line_item_2
        Ledger = f"{Name}\n{data}{Balance_String}"
       
        return Ledger
        
entertainment = Category('Entertainment')
food = Category('Food')
food.deposit(900, 'initial deposit')
food.withdraw(100.67, 'candy')
food.withdraw(45.67, 'milk, cereal, eggs, bacon, bread')
food.get_balance()
food.transfer(100, entertainment)
print(food)

note how there isn’t an asterisk above the last digit of the money amounts, so you need to align things better, you have something that is out one number

like, I have added this code to check:

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('\n\n')
print('''*************Food*************
initial deposit        1000.00
groceries               -10.15
restaurant and more foo -15.89
Transfer to Clothing    -50.00
Total: 923.96''')

and the output in the terminal is this:

notice how there is a different alignment between your output (above) and the expected (below)

Thank you for your help, I figured it out.