Scientific Computing with Python Projects - Budget App

Tell us what’s happening:

I’ve written out and tested the code for the budget app on vscode based off the boilerplate provided on GitHub, however when I insert my code on freeCodeCamp,'s client, all the tests fail, despite passing the same tests provided on GitHub when I run them in my terminal.

I’m not sure if it’s a problem with it being in Beta or not, but would love some guidance!

I have all adblockers disabled for freeCodeCamp as well.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0

Challenge Information:

Scientific Computing with Python Projects - Budget App

Can you please share all of the errors and test output?

If the output looks correct, you most likely have some spaces at the end of your lines which are causing the errors. All of the spacing must match exactly (even if it’s not visible to the eye)

An assertion error gives you a lot of information to track down a problem. For example:

AssertionError: 'Year' != 'Years'
- Year
+ Years
?     +

Your output comes first, and the output that the test expects is second.

AssertionError: ‘Year’ != ‘Years’

Your output: Year does not equal what’s expected: Years

- Year
+ Years
?     +

- Dash indicates the incorrect output
+ Plus shows what it should be
? The Question mark line indicates the place of the character that’s different between the two lines. Here a + is placed under the missing s .

Here’s another example:

E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E       assert '  3801      123    \n   - 2     + 49    \n------    -----    \n' == '  3801      123\n-    2    +  49\n------    -----'
E         -   3801      123
E         +   3801      123    
E         ?                ++++
E         - -    2    +  49
E         +    - 2     + 49    
E         - ------    -----
E         + ------    -----    
E         ?                +++++

The first line is long, and it helps to view it as 2 lines in fixed width characters, so you can compare it character by character:

'  3801      123    \n   - 2     + 49    \n------    -----    \n'
'  3801      123\n-    2    +  49\n------    -----'

Again, your output is first and the expected output is second. Here it’s easy to see extra spaces or \n characters.

E         -   3801      123
E         +   3801      123    
E         ?                ++++

Here the ? line indicates 4 extra spaces at the end of a line using four + symbols. Spaces are a little difficult to see this way, so it’s useful to use both formats together.

I hope this helps interpret your error!

1 Like

Yes assertion errors are all fine! When I run the tests (taken from the boilerplate repository on github, which correspond to this challenge) on vscode, everything passes, no assertion errors or anything. 100% pass.

However, when I try to run any tests on the fCC webpage with my code pasted in, every error comes up failing instantly, with no output log errors provided at all. It feels like a server error, but the other python projects seem to test fine on my end apart from the budget one!

Not quite sure I understand this. How can you tell it’s failing if there is no error?

Can you show a screenshot of the behaviour?

Apologies if that didn’t make sense! Hopefully this clears it up a little bit? I’m really stumped as to what’s causing it.

This is what fCC gives me when I run the code I linked above.

Meanwhile this is what I’m getting when I run the same code on desktop, using this boilerplate

$ C:/Python312/python.exe c:/development_projects/python/BudgetApp/
initial deposit        1000.00
groceries               -10.15
restaurant and more foo -15.89
Transfer to Clothing    -50.00
Total: 923.96
Transfer from Food       50.00
Total: 24.45
Percentage spent by category  
 60| o
 50| o
 40| o
 30| o
 20| o  o
 10| o  o  o
  0| o  o  o
     F  C  A
     o  l  u
     o  o  t
     d  t  o
Ran 11 tests in 0.001s

1 Like

Very nice, this is a new platform that’s been deployed, recently. Could very well have to do with it being beta.

If I paste in my code which I originally wrote on replit 6 months ago, it passes. So basically, it seems ok, but maybe something in your implementation is causing a problem. It’s certainly a bit more complicated than mine (with functions like _deposit)

For example, if I print a test, and then paste in your init code, everything is ok:


class Category:
  def __init__(self, name): = name
    self.ledger = []

the console shows “test” but if I paste in just one more function, it breaks, and no longer prints test.


class Category:
  def __init__(self, name): = name
    self.ledger = []

  def __str__(self) -> str:
    to_string = '{:*^30}\n'.format(
    for entry in self.ledger:
      amount_str = f' {format(entry["amount"], '.2f')}'
      desc_str = '{:<30}'.format(entry["description"])
      trim_index = 30 - len(amount_str)
      to_string += f'{desc_str[:trim_index]}{amount_str}\n'
    to_string += f'Total: {self._get_balance ()}'
    return to_string

“test” is no longer printed. If I do similar tests with my own code “test” always prints ok.

So, I don’t think any of the code is being run, which makes sense for it to fail all the tests when it passes it all locally, there’s some kind of fatal error before it runs the tests.

If I comment out this line, it works:

amount_str = f' {format(entry["amount"], '.2f')}'

that line gets an error on google colab:

File "<ipython-input-4-07c51ac8a64c>", line 9
    amount_str = f' {format(entry["amount"], '.2f')}'
SyntaxError: invalid decimal literal

What version of Python are you using locally?

If I put your code into google collab to run, I get a few syntax errors:

  File "<ipython-input-5-8704df8e4593>", line 88
    spend_chart += f'    {'---'*len(categories)}-\n'
SyntaxError: f-string: expecting '}'

Try sorting those out first?

Might be some version difference with your local environment, or the implementation of the platform, not quite sure at this point.

But the code does generate syntax errors when run on google colab.

Screenshot 2024-03-03 201123

I hope this helps!

1 Like

I was starting to notice that mentioned in the dev tools as an error, but didn’t really consider it much!! It was the f strings!

I’m using Python 3.12 locally, and it looks like there have been changes to f strings in that release. So it makes sense that anything older would be possibly be failing because of it. What’s New In Python 3.12 — Python 3.12.2 documentation

I just changed how i was processing those lines for the print functions and it all works now!

Thanks for the help!

1 Like

Very enlightening, thanks for the link!

I’m not that strong in string formatting myself, so it didn’t stand out to me at all. Definitely an unexpected problem.

Can I ask why you structure it this way, with every function returning another internal function?

  def deposit(self, amount, description=""):
    return self._deposit(amount, description)

Just wanted to get some practice doing private functions, but realizing now I shouldve done two underscores! Sort of re-applying my C# experience as I can.

haha, ok! I thought there was some special reason about keeping functions exposed outside the class simple or something. Thanks for clarifying.

Seems that a single underscore works:

_single_leading_underscore: weak “internal use” indicator. E.g. from M import * does not import objects whose names start with an underscore.