Code running well in local system, but not in replit online interpreter

Tell us what’s happening:
Describe your issue in detail here.
I was solving my first challenge problem in Data Analysis. I ran the same code in Colab and it works perfectly, but when running on Replit, shows the below error.

Your code so far

import numpy as np

def calculate(l):
    if (len(l) == 9):
      arr = np.array(l,dtype=np.int16).reshape((3,3))
      new_arr = {
        'mean': [np.mean(arr,axis=0).tolist(),np.mean(arr,axis=1).tolist(),np.mean(arr).tolist()],
        'variance': [np.var(arr,axis=0).tolist(),np.var(arr,axis=1).tolist(),np.var(arr).tolist()],
        'standard deviation': [np.std(arr,axis=0).tolist(),np.std(arr,axis=1).tolist(),np.std(arr).tolist()],
        'max':[np.max(arr,axis=0).tolist(),np.max(arr,axis=1).tolist(),np.max(arr).tolist()],
        'min':[np.min(arr,axis=0).tolist(),np.min(arr,axis=1).tolist(),np.min(arr).tolist()],
        'sum':[np.sum(arr,axis=0).tolist(),np.sum(arr,axis=1).tolist(),np.sum(arr).tolist()]
        }
      print(new_arr)
    else:
        raise ValueError("List must contain nine numbers.")

Output from Replit

 python main.py
{'mean': [[3.0, 4.0, 5.0], [1.0, 4.0, 7.0], 4.0], 'variance': [[6.0, 6.0, 6.0], [0.6666666666666666, 0.6666666666666666, 0.6666666666666666], 6.666666666666667], 'standard deviation': [[2.449489742783178, 2.449489742783178, 2.449489742783178], [0.816496580927726, 0.816496580927726, 0.816496580927726], 2.581988897471611], 'max': [[6, 7, 8], [2, 5, 8], 8], 'min': [[0, 1, 2], [0, 3, 6], 0], 'sum': [[9, 12, 15], [3, 12, 21], 36]}
None
{'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]}
E{'mean': [[4.666666666666667, 4.333333333333333, 2.6666666666666665], [5.0, 3.0, 3.6666666666666665], 3.888888888888889], 'variance': [[9.555555555555555, 11.555555555555557, 4.222222222222222], [10.666666666666666, 0.0, 14.888888888888891], 9.209876543209875], 'standard deviation': [[3.0912061651652345, 3.39934634239519, 2.0548046676563256], [3.265986323710904, 0.0, 3.8586123009300755], 3.0347778408328137], 'max': [[9, 9, 5], [9, 3, 9], 9], 'min': [[2, 1, 0], [1, 3, 0], 0], 'sum': [[14, 13, 8], [15, 9, 11], 35]}
E.
======================================================================
ERROR: test_calculate (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator/test_module.py", 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/case.py", line 943, in assertAlmostEqual
    diff = abs(first - second)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'dict'

======================================================================
ERROR: test_calculate2 (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator/test_module.py", 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/case.py", line 943, in assertAlmostEqual
    diff = abs(first - second)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'dict'

----------------------------------------------------------------------
Ran 3 tests in 0.003s

FAILED (errors=2)

Your browser information:

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

Challenge: Mean-Variance-Standard Deviation Calculator

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

Thank you, I am new to the forum, will keep this in mind and implement on the next go. :slightly_smiling_face:

You’re function is printing the result array but not returning it. The unit tests are trying to compare the object returned by the function to an expected result but raising a TypeError because they can’t compare the expected object (of type dict) with the return value of the function (NoneType , which is a default return value in Python if you do not specify one).

Oh, did not see that.
Thanks, the result was accepted after the change.