Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator

Tell us what’s happening:
Ran code in Google Collab and works fine but running into this issue in Replit:
ERROR: test_calculate (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/boilerplate-mean-variance-standard-deviation-calculator-1/”, 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 “/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/unittest/”, line 876, in assertAlmostEqual
diff = abs(first - second)
TypeError: unsupported operand type(s) for -: ‘dict’ and ‘dict’

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator

Link to the challenge:

Can you link to your replit, please? Will need to see your code to look into this.

You’re returning a dictionary of lists as in the example?

The values in the returned dictionary should be lists and not Numpy arrays.

I found something, the second list of your min is different.

In the example calculate([0,1,2,3,4,5,6,7,8])

your min:

‘min’: [[0, 1, 2], [2, 5, 8], 0],

and the example min:

‘min’: [[0, 1, 2], [0, 3, 6], 0],

It’s also different in the first failed test:

your output:

‘min’: [[1, 4, 0], [6, 8, 7], 0],


‘min’: [[1, 4, 0], [2, 0, 1], 0],

In the incorrect output I noticed the middle min list is the same as max:

‘max’: [[8, 6, 7], [6, 8, 7], 8],
‘min’: [[1, 4, 0], [6, 8, 7], 0],

and again here:

‘max’: [[6, 7, 8], [2, 5, 8], 8],
‘min’: [[0, 1, 2], [2, 5, 8], 0],

You can also simplify your calculations enormously using matrix operations, that’s really what numpy is for:

You should ideally complete this without using any loops at all. Doing it like this you are missing all of the advantages of numpy matrices.

Thank you so much! Can’t believed i missed something so small like that.

1 Like

It’s quite a wall of numbers to look at and the error is very obtuse

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