def create_spend_chart(categories):
total = 0
final = "Percentage spent by category\n"
for i in categories:
total += i.balance
final += f"100|\n"
for i in range(90,-10,-10):
if i == 0:
final += " "
final += f" {i}|"
for j in categories:
rounded = round(j.balance / 10)*10
if rounded/total * 100 >= i:
final += " o "
else:
final += " "
final += "\n"
final += " " + "-" * ((len(categories) * 3) + 1)
fails = char = 0
while fails < len(categories):
fails = 0
final += "\n "
for i in categories:
try:
if fails > 0:
final += " "
final += i.name[char] + " "
except:
fails += 1
char += 1
return final
Hi, thanks for the help. I’ve made some tweaks and the spacing errors seem to be fixed. However, It’s now giving me an error which looks like it’s expecting a bar to reach a percentage that my program isn’t reaching. I’ve included the data that I believe its using below and I’ve done the percentage calculations myself and I think that they should all be at 30% but the tests are showing one of them to be at 70?
lol yeah it happens ^^
So I guess you can do it now, just a little heads-up: the task wants to round in a specific way.
I didn’t check you code, but this is a common error.