Error in replit project? need help

I am a new on freecodecamp and doing my first froject for DataAnalyst course.
I’ve made my code in Jupyter notebook first. All works well. When passing my code to replit it gave output with 2 errors but I can’t understand the reason. May be it’s that I am an amateur in coding or may be I lack English as it’s not my native language.
Could you tell me what means that type of error?

"ERROR: test_calculate (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/boilerplate-mean-variance-standard-deviation-calculator/”, line 10, in test_calculate
self.assertAlmostEqual(actual, expected, “Expected different output when calling ‘calculate()’ with ‘[2,6,2,8,4,0,1,5,7]’”)
File “/usr/lib/python3.8/unittest/”, line 943, in assertAlmostEqual
diff = abs(first - second)
TypeError: unsupported operand type(s) for -: ‘dict’ and ‘dict’

ERROR: test_calculate2 (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/boilerplate-mean-variance-standard-deviation-calculator/”, line 15, in test_calculate2
self.assertAlmostEqual(actual, expected, “Expected different output when calling ‘calculate()’ with ‘[9,1,5,3,3,3,2,9,0]’”)
File “/usr/lib/python3.8/unittest/”, line 943, in assertAlmostEqual
diff = abs(first - second)
TypeError: unsupported operand type(s) for -: ‘dict’ and ‘dict’"

First things first - this error is VERY misleading. It might be a problem with the assertion-function, that it cannot properly detect the issue…

Because the issue is, that the dictionairy you return is different from the expected dictionairy. This can be a different spelling of a word, a different format of the objects or simply the order within the lists.

Basically, it means the dictionairy you return is “at any point” different from the expected dictionairy. Then the assertion-function completly breaks.

I only figured this out after someone had a nasty error and I had to literally turn both dicts into strings and compare them until I found the issue…
So yeah - this is no amateur or language problem, this specific error is just REALLY not helpful.

Thanks very much. I supposed that it can be that kind of an error (position of lists in dic).
From you answer it seems that in the end my dic is correct , as we need get some statistics info, not expected “picture” in the project. I hope I will get it passed

If you keep having trouble finding it, consider posting a link to your replit and printing your result. As I said this is quite the nasty error and if I or someone else has the time we can help figure out the exact cause.

ok, thanks for help. will try to find the problem myself first.

I’ve found it…as I thought that is the position of lists in dictionery…Actually it’s not a mistake but obviously FCC wants everything to be exactly the same as they planes up to a comma :slight_smile:

1 Like

Trying to solve problems with a second project. It’s strange… The exercise is not a hard one, to calculate average age of men… I’ve made it in Jupyter Notebook… all works… But again Replit shows an error which I can’t understand (description). Also it looks like result of calculation in replit = None.

Can someone give me a hand in understanding how to translate that kind of error descriptions? :slight_smile: Otherwise it’ll be eternal cycle ))))

boilerplate-demographic-data-analyzer-1 - Replit

Ehm, what description? ^^°
Please check again to properly use the formatting options of the forum.

The instructions:

Round all decimals to the nearest tenth.


yes, they are None until you change it. Careful on what test you are looking at, the test output is not in the same order in which you do things, so look at the name of the tests

1 Like

Thanks colleagues )) bit by bit I start to understand how to work with that system)))
Have solved almost all errors

I have two left.
Please, help to find what I am making wrong. :pray:

  1. The first one is about ‘highest_earning_country’. I’ve got USA but system tells it must be Iran. It looks like an error on system part as I checked by different methods. Country which has max% of people with income >50K is USA.
  2. second error is the same task but I need calculate “highest_earning_country_percentage”. I’ve understood that task as to calculate % of people from USA(see #1) with income >50K devided on all people with income >50K. For me that task not described clearly enough…
    boilerplate-demographic-data-analyzer-2 - Replit

No, it’s Iran.
You gonna look for “max% 50K compared to all people IN THAT COUNTRY” - you are propably looking ath the max% globally. Then it is USA, but that wasn’t the task. You gonna need to look at every country and get their “>50K” divided by all people living there.
Also in order to solve the task, you NEED to calculate the percentage in the first place. Hence returning it isn’t really a seperate task.

:pray: :star_struck:
Thanks a lot!!!

I’ve done it)))

I would appreciate if you could give me an advice as I (seems) took very long street to the answer.

When I need to extract an info from a DataFrame/Series, working with selection tools I always get a result as a series and not a single int or string. As a result I pressed to use this “.to list().[ …]” I make it to a list and then take a list element out.

It seems to me that this way is very crooked

I think you can just select the first element of the series via “series[0]” to get the item.

This course (video) is very short and hasty which I like but… when I work on projects I start not only to recheck lessons but also to search for other methods of pandas, etc. Of course I tend to think in terms of methods which I know (heard of) and they may be not at all optimum.
I wanted to ask… Is it a right path? :sweat_smile: :joy:
What method of education is recommended to use? :upside_down_face:
or my “method” is widely used)))))

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