Tell us what’s happening:
Hello world! I have a AssertionError at line 102. I tried for some time and can’t find my mistake maybe im doing it wrong. Time flies by and I dont know what to do… need help on how to do the right spacing. Sorry for my bad english I try x)
Your code so far
Here is my code:
def create_spend_chart(categories):
# Calculate the total amount spent
total_spent = sum(category.get_spent() for category in categories)
# Calculate the percentage spent
percentages = [(category.get_spent() / total_spent) * 100 for category in categories]
# Build the spend chart
chart = "Percentage spent by category\n"
for i in range(100, -10, -10):
chart += f"{i:3d}| "
for percentage in percentages:
if percentage >= i:
chart += "o "
else:
chart += " "
chart += "\n"
# Add the horizontal line
chart += " " + "-" * (3 * len(categories) + 1) + "\n"
# Determine the maximum category name length
max_name_length = max(len(category.category_name) for category in categories)
# Write the category names vertically below the bars
for i in range(max_name_length):
chart += " "
for category in categories:
if i < len(category.category_name):
chart += category.category_name[i] + " "
else:
chart += " "
chart += "\n"
return chart
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Challenge: Scientific Computing with Python Projects - Budget App
Your Output:
‘Perc[364 chars] m \n e \n n \n t \n’
Expected:
'Perc[364 chars] m \n e \n n \n t ’
You have an extra \newline at the very end of your output, which might mean you need to add the newline at the beginning of a string, instead of the end, so the last string just ends without \newline (or however else you want to get rid of it)