Tell us what’s happening:
I can’t figure out what exactly is the problem with the final output.
There are four boxes that are still unchecked
Your code so far
def create_spend_chart(categories):
title = "Percentage spent by category\n"
spent = []
percent = []
strg = ""
for i in categories:
min_sum = 0
for f in i.ledger:
if f['amount'] < 0:
min_sum += (f['amount']*-1)
spent.append(min_sum)
total_spent = sum(spent)
for spending in spent:
perc = (spending * 100)/total_spent
percent.append(perc)
for indx, val in enumerate(percent):
if val % 10 != 0:
rem = val % 10
if rem < 5:
percent[indx] = (val // 10) * 10
if rem >= 5:
new_val = (val // 10) + 1
percent[indx] = new_val * 10
for y in range(100, -1, -10):
strg += (f"{y:>3}|")
for k in (percent):
if k >= y:
strg += (f"{'o':^3}")
strg += '\n'
strg += (f"{'-':>5}")
for _ in range(len(percent) * 3):
strg += ("-")
strg += '\n'
name = [cat.name for cat in categories]
for i in range(len(max(name, key= lambda x:len(x)))):
for indx, j in enumerate(name):
pos = 6 if indx == 0 else 3
try:
strg += (f"{j[i]:>{pos}}")
except IndexError:
strg += (f"{'':>{pos}}")
continue
if i != (len(max(name, key= lambda x:len(x))) - 1):
strg += '\n'
return title + strg
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App - Build a Budget App

