Help needed with budget app

Hi,

I need some help here. I can’t see where is the error.
Just one test is failing. test_create_spend_chart

I counted chars and compare both, but I’ve same number of chars and I can’t see any difference. It’s driving me crazy. Any help?

**class Category:

def __init__(self, category = ''):
    self.category = category
    self.ledger = []
    self.total = 0
def deposit(self, amount, description = ''):
    self.ledger.append({"amount": amount, "description":description})
    self.total = self.total + amount
def withdraw(self, amount, description = ''):
    if (self.total-amount > 0 ):
        self.ledger.append({"amount": amount*(-1), "description":description})
        self.total = self.total - amount
        return True
    else:
        return False
def get_balance(self):
    return self.total
def transfer(self, amount, category):
    if (self.total - amount > 0):
        transferencia = "Transfer from " + self.category
        category.deposit(amount, transferencia)
        self.withdraw(amount, "Transfer to " + category.category)
        return True
    else:
        return False
def check_funds(self, amount):
    if (self.total < amount):
        return False
    else:
        return True

def __str__(self):
    title = f"{self.category:*^30}\n"
    items = ""
    total = 0
    for i in range(len(self.ledger)):
        items += f"{self.ledger[i]['description'][0:23]:23}" + f"{self.ledger[i]['amount']:>7.2f}" + '\n'
    items +='Total: ' +  str(self.total)
    return title + items

def create_spend_chart(categories):
cartera = {}
porcentajes = {}
cantidadTotal =0
longitud = 0
for categor in categories:
cantidad = 0
for l in categor.ledger:
if(l[‘amount’]<0):
cantidad = cantidad + l[‘amount’]
cantidadTotal = cantidadTotal + l[‘amount’]
cartera[categor.category] = cantidad
if(len(categor.category) > longitud):
longitud = len(categor.category)
cart = cartera.items()
for k, v in cart:
percent = v*100/cantidadTotal
r = 100 - percent;
a = r % 10;
percent = percent + a;
porcentajes[k] = int(percent)
num = 100
imprimir = ‘Percentage spent by category\n’
espacio = ‘’
p = porcentajes.items()
for i in range(0, 100, 10):
if(i > 0):
espacio = ’ ’
val = ‘’
final = ‘’
for k,v in p:
if (v > (num-i)):
val += ’ o ’
else:
val += ’ ’
val = val + ’ ’
for k,v in p:
if (v >= 0):
final = final + ’ o ’
else:
final = final + ’ ’
imprimir += espacio + str(num - i) + ‘|’ + val + ‘\n’
imprimir += str(’ 0|’ + final) + ‘\n’
imprimir += ’ ----------\n’
for i in range(longitud):
sentence = ’ ’
for categor in categories:
if(i > len(categor.category)-1):
sentence = sentence + ’ ’
else:
sentence = sentence + ’ ’ + categor.category[i] + ’ ’
imprimir +=sentence + ’ \n’
print(imprimir[:-1])**

This is my link to the code.
https://repl.it/join/yexfgqjn-robertogimenez

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0.

Challenge: Budget App

Link to the challenge:

Error message AssertionError: None != 'Percentage spent[...]
You are supposed to return a string, not to print() it.

2 Likes

Thanks you’re right!