Build a Budget App - Build a Budget App

Tell us what’s happening:
Describe your issue in detail here.

I think i have done everything right but its not even verifying the first challenge. where am i wrong?

Your code so far

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

    def deposit(self, amount, description = ''):
        entry = {'amount': amount, 'description': description}
        self.ledger.append(entry)

    def withdraw(self, amount, description = ''):
        if self.check_funds(amount):
            entry = {'amount': -amount, 'description': description}
            self.ledger.append(entry)
            return True
        return False

    def get_balance(self):
        balance = 0
        for item in self.ledger:
            balance += item['amount']
        return balance

    def transfer(self, amount, Category):
        if self.withdraw(amount, f"Transfer to {Category.name}"):
            Category.deposit(amount, f"Transfer from {self.name}")
            return True
        return False

    def check_funds(self, amount):
        if self.get_balance() >= amount:
            return True
        return False

    def __str__(self):
        final = self.name.center(30, '*') + '\n'
        total = 0
        for item in self.ledger:
            desc = item['description'][0:23]
            amt = f"{item['amount']:.2f}"
            final += f"{desc:<23}{amt:>7}\n"
            total += item['amount']
        return final +  f"Total: {total}"

food = Category('Food')
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant')
clothing = Category('Clothing')
food.transfer(50, clothing)
#print(food)
#print(clothing)
        
        
        
def create_spend_chart(categories):
    total = 0
    for category in categories:
        for item in category.ledger:
					       amt = item['amount']
					       if amt < 0:
						          total += abs(item['amount'])
			
				
    print ('Percentage spent by category')
			 percentages = []
			 for category in categories:
				    spent = 0
				    for item in category.ledger:
					       spent += (abs(item['amount']) if item['amount'] < 0 else 0)
			     percent = (spent / total * 100) // 10 * 10
				    percentages.append(percent)
				
			 for num in range(100, -1, -10):
				    print(f"{num:>3}|", end='')
				    for percent in percentages:
					       if percent >= num:
					           print(" o ", end="")
					       else:
						          print("  ", end="")
				    print()
				
			 last_line = len(percentages)
			 print('    ' + '---' * last_line + '-')
			
			 category_list = []
			 for category in categories:
				    category_list.append(category.name)
				
			 longest = max(category_list, key = len)
			 for i in range(len(longest)):
				    print('     ', end='')
				    for category in category_list:
					       if len(category) > i:
						          print(category[i], end="  ")
					       else:
						          print('   ', end='')
				    print()
				
		

create_spend_chart([food,clothing])

Your mobile information:

CPH2693 - Android 15 - Android SDK 35

Challenge: Build a Budget App - Build a Budget App

Link to the challenge:

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.
Learning to describe problems is hard, but it is an important part of learning how to code.
Also, the more you say, the more we can help!

Hi @Uselesscoder,

I’m seeing this error in the console. Try fixing that before running the tests.

Traceback (most recent call last):
  File "main.py", line 66
                         percentages = []
    ^
TabError: inconsistent use of tabs and spaces in indentation

Happy coding!