Data Analysis: Mean-Variance-Standard Deviation Calculator

I imported the project to replit. When I run my code, it shows - TypeError: unsupported operand type(s) for -: ‘dict’ and ‘dict’ and FAILED (errors=2)

Been searching it on google but i’m kinda lost right now. Here is replit link: boilerplate-mean-variance-standard-deviation-calculator - Replit

In this case it means that result returned by function is different from what test is expecting.

Method used in test is not able to determine what exactly is the difference between two dictionaries, as dict doesn’t support subtraction operation. However that method is still able to confirm when two dictionaries are the same (they have the same keys and values).

1 Like

I believe it is because tests want exact results. For example, if I get:

5.6667

but test wants:

5.6666667 

then it fails the test (that was my experience, at least).

You are going to kick yourself, but:

Your output:

{'mean': [[3.6666666666666665, 5.0, 3.0], [3.3333333333333335, 4.0, 4.333333333333333], 3.888888888888889], 'var': [[9.555555555555557, 0.6666666666666666, 8.666666666666666], [3.555555555555556, 10.666666666666666, 6.222222222222221], 6.987654320987654], 'std': [[3.091206165165235, 0.816496580927726, 2.943920288775949], [1.8856180831641267, 3.265986323710904, 2.494438257849294], 2.6434171674156266], 'max': [[8, 6, 7], [6, 8, 7], 8], 'min': [[1, 4, 0], [2, 0, 1], 0], 'sum': [[11, 15, 9], [10, 12, 13], 35]}

The output that the test expects (which you can refer to in test_module.py):

{'mean': [[3.6666666666666665, 5.0, 3.0], [3.3333333333333335, 4.0, 4.333333333333333], 3.888888888888889], 'variance': [[9.555555555555557, 0.6666666666666666, 8.666666666666666], [3.555555555555556, 10.666666666666666, 6.222222222222221], 6.987654320987654], 'standard deviation': [[3.091206165165235, 0.816496580927726, 2.943920288775949], [1.8856180831641267, 3.265986323710904, 2.494438257849294], 2.6434171674156266], 'max': [[8, 6, 7], [6, 8, 7], 8], 'min': [[1, 4, 0], [2, 0, 1], 0], 'sum': [[11, 15, 9], [10, 12, 13], 35]}

Spot the difference. (All of your numbers are correct)

Yeah, i got it correct. Thanks for checking.

But is it wrong because I used dict? I’m so lost with this.

Your numbers are correct, your key names are wrong. Look again

OMG. Thank you so much. Tunnel vision right there. Thank you so much for checking.

1 Like

Experiencing a ‘TypeError’ can be frustrating, especially when importing a project. It seems like a compatibility issue between data types. Make sure your code is correctly handling dictionaries and their operations. Sometimes reviewing your code logic and data structures can help pinpoint the problem. Also, checking any recent changes you made might provide insights. Keep at it, and don’t hesitate to seek guidance from coding communities. Best of luck in resolving the issue!

Yeah, it was frustrating. I stopped working on this for a week, until I decided to consult here. Luckily, somebody saw that I just forgot to match the titles inside the dictionary. I’m so thankful for the help. Now, I’m working on the second project of Data Analysis with Python.

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