Mean-Variance-Standard - Unsupported operand type(s)

Still struggling

def calculate(list):
  calculations = {}
  try:
    a = np.array(list).reshape(3, 3)
  except:
    raise ValueError('List must contain nine numbers.')
  calculations['mean'] = [a.mean(axis=0).tolist(), a.mean(axis=1).tolist(), a.mean()]
  calculations['variance'] = [a.var(axis=0).tolist(), a.var(axis=1).tolist(), a.var()]
  calculations['standart deviation'] = [a.std(axis=0).tolist(), a.std(axis=1).tolist(), a.std()]
  calculations['max'] = [a.max(axis=0).tolist(), a.max(axis=1).tolist(), a.max()]
  calculations['min'] = [a.min(axis=0).tolist(), a.min(axis=1).tolist(), a.min()]
  calculations['sum'] = [a.sum(axis=0).tolist(), a.sum(axis=1).tolist(), a.sum()]
  
  return calculations

2 same errors occured:

ERROR: test_calculate2 (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator-1/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 -: 'dict' and 'dict'

----------------------------------------------------------------------
Ran 3 tests in 0.011s

FAILED (errors=2)
 

Holy guacamole!!!
I’ve catch crazy “standarD deviation” bug!
Fixed by now)

1 Like

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