My solution for the mean-variance-std project works in Jupyter Notebook but fails one fCC test

Tell us what’s happening:
My solution for the mean-variance-std project passes the first two tests. But, it fails to show the error message when a list that is not equal to 9 is passed. My solution works fine in Jupyter Notebook and I cannot figure out why it fails the fCC test. Any help or suggestions would be appreciated. Thanks.

Your code so far
import numpy as np

#a = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8])

def calculate(list):
if len(list) != 9:
return “List must contain nine numbers.”

x = np.array(list).reshape(3, 3)

mean0 = np.mean(x, axis=0).tolist() # collapses rows
mean1 = np.mean(x, axis=1).tolist() # collapses columns
meanN = np.mean(x, None).tolist()
var0 = np.var(x, axis=0).tolist() # collapses rows
var1 = np.var(x, axis=1).tolist() # collapses columns
varN = np.var(x, None).tolist()
std0 = np.std(x, axis=0).tolist() # collapses rows
std1 = np.std(x, axis=1).tolist() # collapses columns
stdN = np.std(x, None).tolist()
max0 = np.max(x, axis=0).tolist() # collapses rows
max1 = np.max(x, axis=1).tolist() # collapses columns
maxN = np.max(x, None).tolist()
min0 = np.min(x, axis=0).tolist() # collapses rows
min1 = np.min(x, axis=1).tolist() # collapses columns
minN = np.min(x, None).tolist()
sum0 = np.sum(x, axis=0).tolist() # collapses rows
sum1 = np.sum(x, axis=1).tolist() # collapses columns
sumN = np.sum(x, None).tolist()

values = [[mean0, mean1, meanN], [var0, var1, varN],
      [std0, std1, stdN], [max0, max1, maxN],
      [min0, min1, minN], [sum0, sum1, sumN]]

keys = ["mean", "variance", "standard deviation", "max", "min", "sum"]

result = {keys[i]: values[i] for i in range(len(keys))}

return result

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0

Challenge: Mean-Variance-Standard Deviation Calculator

Link to the challenge:

It’s expected for the function to raise ValueError exception, when there isn’t nine numbers, not to just return string.

Thanks, sanity. I misunderstood that the test failure was because my code did not raise a ValueError even though it caught the wrong list size. My misunderstanding occurred even though the failure notice specifically said ‘AssertionError: ValueError not raised by calculate.’ I do not have much experience with python testing, so thanks for helping me learn a little more more about the subject.

I plan to research any future error messages I get more thoroughly and will spend some time studying python testing so I do not make such a simple mistake again. Gary

1 Like