Scientific Computing with Python Projects - Budget App

Hey everybody,
it seems like I can’t figure out why my code fails on two tests. Even though I can’t see a difference in the terminal prints. I posted my link below. I’m also grateful for any advice how to read the comments on why it failed better. Because I feel like I should be able to figure that one out myself, but I’m a bit lost.
Thanks for any advice!

Mycode so far

boilerplate-budget-app - Replit

My browser information:

User Agent is: Chrome/110.0.0.0

Challenge: Scientific Computing with Python Projects - Budget App

Link to the challenge:

You have a few issues.

Your calculation for the percentages is not correct.

You are missing some spaces on some of the lines and have added extra lines/spaces where not needed.

To make it easier to see the spaces, I have replaced them with ``.

Expected:

Percentage☐spent☐by☐category
100|☐☐☐☐☐☐☐☐☐☐
☐90|☐☐☐☐☐☐☐☐☐☐
☐80|☐☐☐☐☐☐☐☐☐☐
☐70|☐☐☐☐o☐☐☐☐☐
☐60|☐☐☐☐o☐☐☐☐☐
☐50|☐☐☐☐o☐☐☐☐☐
☐40|☐☐☐☐o☐☐☐☐☐
☐30|☐☐☐☐o☐☐☐☐☐
☐20|☐☐☐☐o☐☐o☐☐
☐10|☐☐☐☐o☐☐o☐☐
☐☐0|☐o☐☐o☐☐o☐☐
☐☐☐☐----------
☐☐☐☐☐B☐☐F☐☐E☐☐
☐☐☐☐☐u☐☐o☐☐n☐☐
☐☐☐☐☐s☐☐o☐☐t☐☐
☐☐☐☐☐i☐☐d☐☐e☐☐
☐☐☐☐☐n☐☐☐☐☐r☐☐
☐☐☐☐☐e☐☐☐☐☐t☐☐
☐☐☐☐☐s☐☐☐☐☐a☐☐
☐☐☐☐☐s☐☐☐☐☐i☐☐
☐☐☐☐☐☐☐☐☐☐☐n☐☐
☐☐☐☐☐☐☐☐☐☐☐m☐☐
☐☐☐☐☐☐☐☐☐☐☐e☐☐
☐☐☐☐☐☐☐☐☐☐☐n☐☐
☐☐☐☐☐☐☐☐☐☐☐t☐☐

What your function returns:

Percentage☐spent☐by☐category☐
100|☐☐☐☐☐☐☐☐☐
☐90|☐☐☐☐☐☐☐☐☐
☐80|☐☐☐☐☐☐☐☐☐
☐70|☐☐☐☐☐☐☐☐☐
☐60|☐☐☐☐☐☐☐☐☐
☐50|☐☐☐☐☐☐☐☐☐
☐40|☐☐☐☐o☐☐☐☐
☐30|☐☐☐☐o☐☐☐☐
☐20|☐☐☐☐o☐☐☐☐
☐10|☐☐☐☐o☐☐o☐
☐☐0|☐o☐☐o☐☐o☐
☐☐☐☐----------
☐☐☐☐☐B☐☐F☐☐E☐
☐☐☐☐☐u☐☐o☐☐n☐
☐☐☐☐☐s☐☐o☐☐t☐
☐☐☐☐☐i☐☐d☐☐e☐
☐☐☐☐☐n☐☐☐☐☐r☐
☐☐☐☐☐e☐☐☐☐☐t☐
☐☐☐☐☐s☐☐☐☐☐a☐
☐☐☐☐☐s☐☐☐☐☐i☐
☐☐☐☐☐☐☐☐☐☐☐n☐
☐☐☐☐☐☐☐☐☐☐☐m☐
☐☐☐☐☐☐☐☐☐☐☐e☐
☐☐☐☐☐☐☐☐☐☐☐n☐
☐☐☐☐☐☐☐☐☐☐☐t☐
☐☐☐☐☐☐☐☐☐☐☐☐☐
1 Like

Thanks a lot. Replacing the spaces by a visible character is a great idea and helped a lot, and I found a few mistakes. I appreciate that.

Sadly, there is still an issue I can’t figure out. Like you said, the unittest says the percentages are wrong. But when I use the same setup as in the test and compare the expected string with my created string, they are exact the same (You can see it in my et.py). So I don’t know how to fix this issue. I would really appreciate a hint on how to approach this issue.

et.py:

import budget
from budget import create_spend_chart


business = budget.Category("Business")
food = budget.Category("Food")
entertainment = budget.Category("Entertainment")

# the settings from the test case from test_module.py
food.deposit(900, "deposit")
entertainment.deposit(900, "deposit")
business.deposit(900, "deposit")
food.withdraw(105.55)
entertainment.withdraw(33.40)
business.withdraw(10.99)

# string created by using my budget.py
string_from_budget_app = create_spend_chart(budget.Category.categories)


string_from_test_module = "Percentage spent by category\n100|          \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  "

print(string_from_budget_app, string_from_test_module)

print(string_from_test_module == string_from_test_module)

Print:

Percentage spent by category
100|          
 90|          
 80|          
 70|    o     
 60|    o     
 50|    o     
 40|    o     
 30|    o     
 20|    o  o  
 10|    o  o  
  0| o  o  o  
    ----------
     B  F  E  
     u  o  n  
     s  o  t  
     i  d  e  
     n     r  
     e     t  
     s     a  
     s     i  
           n  
           m  
           e  
           n  
           t  
 Percentage spent by category
100|          
 90|          
 80|          
 70|    o     
 60|    o     
 50|    o     
 40|    o     
 30|    o     
 20|    o  o  
 10|    o  o  
  0| o  o  o  
    ----------
     B  F  E  
     u  o  n  
     s  o  t  
     i  d  e  
     n     r  
     e     t  
     s     a  
     s     i  
           n  
           m  
           e  
           n  
           t  
True

One of the main issues you have is that you have a create a class method named get_withdraw_distribution. You end up getting the withdrawals across all the test transactions for each budget category that are tested in test_module.py, instead of just the instance of Category that is created for each test.

I was able to make a few minor changes to your functions and get everything to pass.

Make get_withdraw_distribution a stand-alone function (not a classmethod and not evne a method of Category with a single parameter named categories. You will of course need to pass categories as an argument from within the create_spend_chart when you call it.

Get rid of all the class methods because you do not need them.

Unrelated to the percent calculations, but you still need to get rid of the extra \n that you are adding to the end of the string that gets returned.

1 Like

Thanks, it works!
I really still don’t get how:

print(string_from_test_module == string_from_test_module)

could reply True while there were obviously differences.
If you have an idea about that or can give me a hint, that would be great!

Thanks for the amazing help! :slight_smile:

Above, you are comparing string_from_test_module to string_from_test_module. Those will always be equal, so this will be True.

1 Like

I can’t believe I didn’t see this. I’m so done… Thanks for your patience. I’m gonna go and find a hole to bury myself. :wink: