Tell us what’s happening:
I have been trying to solve “create_spend_chart” for weeks now. The code works perfectly and is able to create the chart as described in the read.me file. But, somehow there is an assertion error during testing. Please help !! I want to complete all the projects and get certified.
Your code so far
def create_spend_chart(list_name):
withdrawls = []
categories_name = []
percents = []
for name in list_name:
temp = 0
categories_name.append(name.name.title())
for items in name.ledger:
item = list(items.values())
if item[0] >= 0:
continue
else:
temp = temp + (-(item[0]))
withdrawls.append(temp)
# print(withdrawls)
list_num = list(range(0,101, 10))[::-1]
output = "Percentage spent by category\n"
#calculating percents
total = sum(withdrawls)
for x in range(len(withdrawls)):
per = withdrawls[x] / total
per = int(round(per * 100, -1))
percents.append(per)
# print(percents)
for num in list_num:
print_str = str(num).rjust(3) + "|"
for per in percents:
if per < num:
print_str += " "
else:
print_str += " o "
output += print_str + "\n"
dash_string = " " * 4 + "-" * (3 * len(withdrawls) + 1)
output = output + dash_string
maxlength = len(max(categories_name, key = len))
vertical_output = ""
for i in range(maxlength):
vertical_name = 4 * " "
for name in categories_name:
try:
vertical_name += " " + str(name)[i] + " "
except IndexError:
vertical_name += " "
vertical_output += vertical_name + "\n"
output = output + "\n" + vertical_output
return output
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
.
Challenge: Budget App
Link to the challenge: