KeyError in Budget App

I am running into a KeyError problem with my Budget App.
Here is the hyperlink:

https://replit.com/@Thrashbang/Budget-App#main.py

Could paste the full traceback of the error?

The IDE that I am using, Replit, will not allow me to copy the traceback, if you run the project, you can see the traceback.

You need to select then right-click copy to copy the messages:

Traceback (most recent call last):
  File "/home/runner/ThrashbangBudget-App/main.py", line 166, in <module>
    create_spend_chart([cars])
  File "/home/runner/ThrashbangBudget-App/main.py", line 70, in create_spend_chart
    percent_spent = round(sum(entry["amount"] for entry in category.ledger) / initial_deposits[category.name] * 100)
KeyError: 'Cars'

First, you should have had a different file, you’re not to code everything in main.py. Originally the boilerplate should have a budget.py. The tests will import from budget.py so without it the automated tests will not work.

The automated tests will also be called from main.py but those lines are missing now. It would have looked like this:

# Run unit tests automatically
main(module='test_module', exit=False)

You’ll need to copy a new boilerplate and copy your code into the correct budget.py file.

As for the error, it’s on Line 70:
main.py", line 70
trying to access the key stored in the category variable so I printed it out:

for category in categories:
      print(category) #I added this print
      percent_spent = round(sum(entry["amount"] for entry in category.ledger) / initial_deposits[category.name] * 100)

The result of the print:

<__main__.Category object at 0x7f3d98aa9ed0>

It’s printing an object instead of the name property of the object.

I hope this helps!

Python I was very close to my certification when I came across some issues with this project, thank you so much.