Tell us what’s happening:
i was doing the “build a budget app” and i finished the graph and it have the same format as the given output however the site doesn’t consider it as done why even the test 17 which is just printing the title isn’t consider as done
Your code so far
class Category:
def __init__(self,name):
self.name =name
self.ledger =[]
self.balence=0
self.spent =0
def deposit(self,amount,description=""):
self.ledger.append({'amount': amount, 'description': description})
def withdraw(self,amount,description=""):
if self.get_balance() >= amount:
self.ledger.append({'amount': -amount, 'description': description})
return True
else:
return False
def get_balance(self):
bal=0
for leg in self.ledger:
for val in leg.values():
if isinstance(val,int)or isinstance(val,float):
bal+=val
self.balence = bal
return bal
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
return False
def check_funds(self, amount):
return True if self.get_balance() >= amount else False
def __str__(self):
title = f"{self.name:*^30}\n"
items = ''
for item in self.ledger:
description = item['description'][:23]
amount = f"{item['amount']:.2f}"
items +=f"{description:<23}{amount:>7}\n"
total = f"Total: {self.get_balance():.2f}"
return f"{title}{items}{total}"
def total_spent(self):
sp = 0
for item in self.ledger:
amount = item['amount']
if amount < 0:
sp += -amount
self.spent = sp
return sp
def create_spend_chart(categories):
title = "\nPercentage spent by category"
total =0
for categorie in categories:
total += categorie.total_spent()
percent ={}
for categorie in categories:
x =round(categorie.total_spent()/total*100)
x = rounder(x)
percent.update({""+categorie.name: x})
print(title)
for i in reversed(range(11)):
dot = "o"
x =""
for categorie in categories:
if percent[categorie.name] > (i-1)*10:
x+= dot+" "
if i == 10:
print(f"{i*10}| {x}")
elif i ==0:
print(f" 0| {x}")
else:
print(f" {i*10}| {x}")
print(" ----------")
lon= longer(categories)
for i in range(lon):
y = " "
for categorie in categories:
try:
y += categorie.name[i]+" "
except IndexError:
y+= " "
print(y)
def longer(categories):
ma= -1
for categorie in categories:
if ma < len(categorie.name):
ma = len(categorie.name)
return ma
def rounder(x):
return x//10*10
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')
clothing.deposit(1000, 'initial deposit')
clothing.withdraw(200, 'd')
food.transfer(50, clothing)
print(food)
create_spend_chart([clothing,food])
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 OPR/133.0.0.0
Challenge Information:
Build a Budget App - Build a Budget App
