I have created almost identical chart according to README.md. But still it is giving me a fail. I can’t find the difference what am I doing wrong. I also looked in the forum regarding this challenge and learned from this solution = [Python Budget App -- create_spend_chart function is killing me]
Your code so far
def create_spend_chart(categories):
cat_totals = []
for cat in categories:
total = 0
for c in cat.ledger:
if c['amount'] < 0:
total += c['amount']
else:
pass
cat_totals.append(total)
perc_totals = [int(x/sum(cat_totals) * 10)/10 for x in cat_totals]
i = 100
res = 'Percentage spent by category' + '\n'
while i >= 0:
spc = ' '
for value in perc_totals:
if value * 100 >= i:
spc += 'o '
else:
spc += ' '
if i == 0:
res += str(i).rjust(3) + '|' + spc
else:
res += str(i).rjust(3) + '|' + spc + '\n'
i -= 10
#need categories name
cat_names = [x.category for x in categories]
dashes = '-' + '---' * len(cat_names)
res += '\n' + ' ' * 4 + dashes.rjust(3)
maxi = len(max(cat_names, key = len))
names = ' ' * 4
for i in range(maxi):
for name in cat_names:
try:
names += ' ' + name[i] + ' '
except IndexError:
names += ' '
if i == maxi - 1:
names += ' ' * 4
else:
names += '\n' + ' ' * 4
res += '\n' + names
return res
And can string transposition help?
Challenge: Budget App
Link to the challenge:
https://www.freecodecamp.org/learn/scientific-computing-with-python/scientific-computing-with-python-projects/budget-app