Problem with Mean-Variance-Standard Deviation Calculator projetct

Tell us what’s happening:
Describe your issue in detail here.

Hi! Im new in this plataform, hope to get along with everyone!
So for my issue, i’m getting this error and i dont know what to do anymore

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]}
EE.
======================================================================
ERROR: test_calculate (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator-1/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.
 python main.py
{'sum': [[9, 12, 15], [3, 12, 21], 36]}
EE.
======================================================================
ERROR: test_calculate (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator-1/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.
 python main.py
{'sum': [[9, 12, 15], [3, 12, 21], 36]}
EE.
======================================================================
ERROR: test_calculate (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator-1/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.
 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]}
EE.
======================================================================
ERROR: test_calculate (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator-1/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.
 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]}
EE.
======================================================================
ERROR: test_calculate (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator-1/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 -: 'dict' and 'dict'

======================================================================
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.025s

FAILED (errors=2)

I’ve looked into most of the forum posts and none of the solutions work for me

Your code so far

import numpy as np

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

  calculations["sum"] = [
    array.sum(axis = 0).tolist(),
    array.sum(axis = 1).tolist(),
    array.sum()
  ]
    
  return calculations

Your browser information:

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

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

Read again that problem. They said, Solution should be in the format—

  1. Sum
    2.variance
  2. Standard Deviation

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