Python Budget App issue

Hi everyone,

Similar issues observed on my end. My results are exactly same as @hannesWe’s.

Firstly, I think the description of the create_spend_chart problem is confusing:

The chart should show the percentage spent in each category passed in to the function. The percentage spent should be calculated only with withdrawals and not with deposits.

I’m pretty good with math, and I have never seen or read a percentage calculation described like that - especially when dealing with accounting. I had to work backwards from the unit tests’ bar chart and the cryptic “should be calculated only with withdrawals” to figure out that the task was to: calculate the amount spent in each category (i.e. each category’s total withdrawals) as a percentage of the sum total withdrawals from all the categories passed in to the function.

To make it clearer:

  • the ‘food’ category had only 1 withdraw: 105.55
  • the entertainment category had only 1 withdraw: 33.40
  • the business category also had only 1 withdraw: 10.99

So ‘sum total withdrawals’ = 105.55+33.40+10.99 = 149.94
And each respective “percentage spent” would therefore be:

  • ‘food’: (105.55 / 149.94) *100 = 70.39%
    And you can work out the rest from there…

Which brings me to the second issue. This is the screenshot from the unit-tests results:


I am still new to coding but I believe it is saying that the percentage spent for Business should be 0% (i.e. there should ‘{space}’ and not ‘o’ at the level 10 bar). I think this is wrong but again I am happy to be corrected. The percentage spent for Business category can be easily calculated as 7.33% (as I described above), and this evaluates to 10% (“rounded to the nearest tenth”, as the instructions say). If I am correct, then the test module is incorrect on the last unit test - there should be ‘o’ at that level 10 bar.

I took the liberty of editing my test module’s last unit test to have a ‘o’ instead of the space and re-ran the file, and all tests passed. If there’s an admin-level forum member able to correct/confirm my observations, it’d be appreciated. Thanks!

You definitely should not be editing the tests. Check the instructions for rounding again. You’re correct, it’s not explained very well and it’s not intuitive at all!

EDIT:

The height of each bar should be rounded down to the nearest 10.

Very well, I’ve removed my edit to the test.

I do have to state it for posterity that, just because the instructions say “round down”, rounding 7.3% to 0% is neither mathematically nor statistically correct.

1 Like

The error you’re seeing seems to be related to a Python unit test using the assertEqual method, commonly used in testing frameworks like unittest . The error occurs on line 102 and suggests that the actual value does not match the expected value, and the custom error message is indicating that the chart representation is not as expected.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.