Tell us what’s happening:
I´ve completed the first project of Data Analysis Cert and when run the tests I´m receiving folowing error. (I tried this first into Spyder and worked ok):
======================================================================
ERROR: test_calculate (test_module.UnitTests)
Traceback (most recent call last):
File “/home/runner/AmbitiousGreedyAfkgaming/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/AmbitiousGreedyAfkgaming/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’
======================================================================
FAIL: test_calculate_with_few_digits (test_module.UnitTests)
Traceback (most recent call last):
File “/home/runner/AmbitiousGreedyAfkgaming/test_module.py”, line 18, in test_calculate_with_few_digits
self.assertRaisesRegex(ValueError, “List must contain nine numbers.”, mean_var_std.calculate, [2,6,2,8,4,0,1,])
AssertionError: ValueError not raised by calculate
Ran 3 tests in 0.036s
FAILED (failures=1, errors=2)
KeyboardInterrupt
Your code so far
import numpy as np
def calculate(list):
if len(list) < 9:
print("ValueError: List must contain nine numbers.")
else:
array_1 = np.array(list)
array_1 = array_1.reshape(3,3)
mean = [(np.mean(array_1,axis=0)).tolist(),(np.mean(array_1,axis=1)).tolist(),np.mean(array_1)]
variance = [(np.var(array_1,axis=0)).tolist(),(np.var(array_1,axis=1)).tolist(),np.var(array_1)]
stdev = [(np.std(array_1,axis=0)).tolist(),(np.std(array_1,axis=1)).tolist(),np.std(array_1)]
maxn = [(np.max(array_1,axis=0)).tolist(),(np.max(array_1,axis=1)).tolist(),np.max(array_1)]
minn = [(np.min(array_1,axis=0)).tolist(),(np.min(array_1,axis=1)).tolist(),np.min(array_1)]
sumn = [(np.sum(array_1,axis=0)).tolist(),(np.sum(array_1,axis=1)).tolist(),np.sum(array_1)]
calculations = {
"mean": mean,
"variance": variance,
"stdev": stdev,
"maxn": maxn,
"minn": minn,
"sumn": sumn
}
return calculations
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
.
Challenge: Mean-Variance-Standard Deviation Calculator
Link to the challenge: