Hey everyone, so I’ve been trying to make the create_spend_chart function in the budget app project and I’m definitely stuck. I have percentages already rounded and ready to go but I don’t know how to make actual design of the chart.
This is what I have so far:
def create_spend_chart(categories):
if len(categories) > 4:
return "You can only enter 4 categories at once."
count = 0
total_percentage = categories[count].total_withdraws
for i in range(1):
count += 1
total_percentage += categories[count].total_withdraws
for category in categories:
category_percentages.append(int(round((category.total_withdraws / total_percentage) * 100, -1) / 10))
I would appreciate it a lot if you can help me out with how to start making this function or the basic concept and what I need to do.
Thank you in advance!
Here’s the test chart from that project for reference:
"Percentage spent by category\n"
"100| \n"
" 90| \n"
" 80| \n"
" 70| o \n"
" 60| o \n"
" 50| o \n"
" 40| o \n"
" 30| o \n"
" 20| o o \n"
" 10| o o \n"
" 0| o o o \n"
" ----------\n"
" B F E \n"
" u o n \n"
" s o t \n"
" i d e \n"
" n r \n"
" e t \n"
" s a \n"
" s i \n"
" n \n"
" m \n"
" e \n"
" n \n"
" t "
with the newlines helpfully printed. If you’ve got the data, now you just need to eat the elephant. Create the title line and the dashed line. Create the 100 line. Then create all 11 number lines (go easy, make them all 100). Then get them to count down to zero. Then get the spacing correct. Then write a conditional to change a space to an o if bar should be there for one category and keep the spacing correct. Then loop over all the categories each time, keeping the spacing correct. Then create the top line of the category labels, and then loop through until the longest one is exhausted, keeping the spacing correct.