Traceback (most recent call last):
File “/home/runner/boilerplate-demographic-data-analyzer/test_module.py”, line 27, in test_higher_education_rich
self.assertAlmostEqual(actual, expected, msg=“Expected different value for percentage with higher education that earn >50K.”)
File “/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/unittest/case.py”, line 876, in assertAlmostEqual
diff = abs(first - second)
TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘float’
This question has already been asked twice in here, however, none of the answers help me. Any idea? Running the code in Jupyter notebook raises no error and returns the expected results. Thanks
The important part of the error is: TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘float’.
Which means that somewhere the code is trying to take a “NoneTyoe” (None aka nothing) and try to substract a float of this.
To figure out where this happens we can look at the line they give us: File “/home/runner/boilerplate-demographic-data-analyzer/test_module.py”, line 27, in test_higher_education_rich
So in line 27 of test_module.py you can see the following code:
self.assertAlmostEqual(actual, expected, msg="Expected different value for percentage with higher education that earn >50K.")
The expected part you can see is assigned on line 26 as expected = 46.5 (which is a float).
The actual part is what you have defined, which they try to access in line 25 actual = self.data['higher_education_rich'].
Which the error is telling us is None.
So if we look at your code to figure out why it is None we can see that you most definitly gave it data on line 26 demographic_data_analyzer.py. But then in line 41 of demographic_data_analyzer.py it’s set back to None.
(The same thing happened to lower_education_rich).
So if you remove those None assignements of the variables/data you already figured out you should be able to pass those sections.
I think they originally intended you to replace the var = None with the actual code to get the data.
I see it now!
HungryBee, thank you very much for your help. I definetely did not expect to look at this place, I was looking into my code where the “none” took place.
Thank you once again!