Build a Budget App Project - Build a Budget App Project

Tell us what’s happening:

I dont know what i did wrong to get the last check, because visually its the same as in the example

Your code so far

class Category:
    def __init__(self, name):
        self.name = name
        self.ledger = []
        self.balance = 0
        self.ori_balance = 0
    
    def __str__(self):
        self.counter = 0
        self.printing = ""
        for i in self.ledger:
            self.amounting = f"{self.ledger[self.counter]['amount']:.2f}"
            self.printing += f"{self.ledger[self.counter]['description'][:23]:<23}{self.amounting:>7}\n"
            self.counter += 1
        
        return str(f"*" * int((30-len(self.name)) / 2) + f"{self.name}" + f"*" * int((30-len(self.name)) / 2) + "\n" + self.printing + "Total: " + str(self.balance))

    def deposit(self, amount, description=""):
        self.balance += amount
        self.ori_balance += amount
        self.ledger.append({'amount': amount, 'description': description})

    def withdraw(self, amount, description=""):
        if self.check_funds(amount):
            self.balance -= amount
            self.ledger.append({'amount': -amount, 'description': description})
            return True
        else:
            return False
        
    def get_balance(self):
        return self.balance
    
    def transfer(self, amount, category2):
        if self.check_funds(amount):
            self.withdraw(amount, f"Transfer to {category2.name}")
            category2.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 create_spend_chart(categories):
    counter = -1
    output = "     "
    withdrawal = 0
    percentages = {
        10: "",
        9:"",
        8:"",
        7:"",
        6:"",
        5:"",
        4:"",
        3:"",
        2:"",
        1:"",
        0:"",
    }
    print("Percentage spent by category")
    for i in categories:
        withdrawal += (i.ori_balance - i.balance)

    for i in categories:
        percentage = int((i.ori_balance - i.balance) * 100 / withdrawal)
        for j in range(int(percentage/10), -1, -1):
            percentages[j] += " o "

    for i in range(10, -1, -1):
        print(f"{i}0|{percentages[i]}" if i == 10 else f" {i}0|{percentages[i]}" if i != 0 else f"  {i}|{percentages[i]}")
    print(f"    " + "-" * (len(categories) * 3 + 1))

    listo = []
    for i in categories:
        listo.append(str(i.name))
    longest = ""

    for i in listo:
        if len(i) > len(longest):
            longest = i

    for j in range(len(longest)):    
        counter += 1

        for i in categories:
            try:
                if i.name[counter] is not "":
                    output += i.name[counter] + "  "
                else:
                    output += "    "
            except:
                output += "   "
    
        if counter < len(longest)-1:
            output += "\n     "
        elif counter == len(longest):
            output += ""
        else:
            break
    print(output)




food = Category('Food')
food.deposit(1000, 'deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
auto = Category('Auto')
auto.deposit(2000, "hahh")
food.transfer(50, clothing)
clothing.deposit(400, "dad")
clothing.withdraw(200, "blah")

create_spend_chart([food, clothing, auto])

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 OPR/109.0.0.0

Challenge Information:

Build a Budget App Project - Build a Budget App Project

1 Like

I changed it to actually meet the criteria but it still doesnt work although it looks the same in my opionion

class Category:
def init(self, name):
self.name = name
self.ledger =
self.balance = 0
self.ori_balance = 0

def __str__(self):
    self.counter = 0
    self.printing = ""
    for i in self.ledger:
        self.amounting = f"{self.ledger[self.counter]['amount']:.2f}"
        self.printing += f"{self.ledger[self.counter]['description'][:23]:<23}{self.amounting:>7}\n"
        self.counter += 1
    
    return str(f"{self.name:*^30}\n" + self.printing + "Total: " + str(self.balance))

def deposit(self, amount, description=""):
    self.balance += amount
    self.ori_balance += amount
    self.ledger.append({'amount': amount, 'description': description})

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

def transfer(self, amount, category2):
    if self.check_funds(amount):
        self.withdraw(amount, f"Transfer to {category2.name}")
        category2.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 create_spend_chart(categories):
counter = -1
output = " "
withdrawal = 0
percentages = {
10: “”,
9:“”,
8:“”,
7:“”,
6:“”,
5:“”,
4:“”,
3:“”,
2:“”,
1:“”,
0:“”,
}
goofy = “”

goofy += "Percentage spent by category\n"
for i in categories:
    for k in range(len(i.ledger)):
        withdrawal += i.ledger[k]["amount"] if i.ledger[k]["amount"] < 0 else 0

withdrawal = withdrawal * -1

for i in categories:
    cost = 0
    for k in range(len(i.ledger)):
        cost += int(i.ledger[k]["amount"] * -1) if i.ledger[k]["amount"] < 0 else 0
    percentage = int((cost * 100 / withdrawal) - int((cost * 100 / withdrawal) % 10))
    for j in range(0, 11, 1):
        if percentage >= (j*10):
            percentages[j] += " o "
        else:
            percentages[j] += "   "
        


for i in range(10, -1, -1):
    goofy += f"{i}0|{percentages[i]}\n" if i == 10 else f" {i}0|{percentages[i]}\n" if i != 0 else f"  {i}|{percentages[i]}\n"
goofy += f"    " + "-" * (len(categories) * 3 + 1) + "\n"

listo = []
for i in categories:
    listo.append(str(i.name))
longest = ""

for i in listo:
    if len(i) > len(longest):
        longest = i

for j in range(len(longest)):    
    counter += 1

    for i in categories:
        try:
            if i.name[counter] is not "":
                output += i.name[counter] + "  "
            else:
                output += "    "
        except:
            output += "   "

    if counter < len(longest)-1:
        output += "\n     "
    elif counter == len(longest):
        output += ""
    else:
        break

output = goofy + output
print(output)
return output

food = Category(‘Food’)
food.deposit(1000, ‘deposit’)
food.withdraw(200, ‘groceries’)
food.withdraw(150, ‘restaurant and more food for dessert’)
clothing = Category(‘Clothing’)
auto = Category(‘Auto’)
auto.deposit(2000, “hahh”)
food.transfer(50, clothing)
clothing.deposit(400, “dad”)
clothing.withdraw(200, “blah”)
auto.withdraw(700, “blah”)
food.deposit(300, “dawda”)
alpha = Category(“Alpha”)

create_spend_chart([food, clothing, auto, alpha])

I’m currently experiencing the same exact problem. I hope someone delivers a solution to this soon