Tell us what’s happening:
I’m not sure if I’m misunderstanding the instructions, but I’m having passing the ValueError unit test.
I raised the error as instructed, but as a result my unit tests seem not to be running, and I’m technically not ‘passing’ any of the tests, because I believe they don’t run?
I also tried catching the error and returning it, however this results in me failing the tests because I’m not raising the ValueError?
link to replit:
Your code so far
import numpy as np
def calcMeans(matrix):
overallMean = np.mean(matrix).tolist()
rowMean = np.mean(matrix, axis = 0).tolist()
colMean = np.mean(matrix, axis = 1).tolist()
return [rowMean, colMean, overallMean]
def calcVariance(matrix):
overallVar = np.var(matrix).tolist()
rowVar = np.var(matrix, axis = 0).tolist()
colVar = np.var(matrix, axis = 1).tolist()
return [rowVar, colVar, overallVar]
def calcStd(matrix):
overallStd = np.std(matrix).tolist()
rowStd = np.std(matrix, axis = 0).tolist()
colStd = np.std(matrix, axis = 1).tolist()
return [rowStd, colStd, overallStd]
def calcMax(matrix):
overallMax = np.max(matrix).tolist()
rowMax = np.max(matrix, axis = 0).tolist()
colMax = np.max(matrix, axis = 1).tolist()
return [rowMax, colMax, overallMax]
def calcMin(matrix):
overallMin = np.min(matrix).tolist()
rowMin = np.min(matrix, axis = 0).tolist()
colMin = np.min(matrix, axis = 1).tolist()
return [rowMin, colMin, overallMin]
def calcSum(matrix):
overallSum = np.sum(matrix).tolist()
rowSum = np.sum(matrix, axis = 0).tolist()
colSum = np.sum(matrix, axis = 1).tolist()
return [rowSum, colSum, overallSum]
def calculate(list):
if len(list)!=9:
msg = "List must contain nine numbers."
raise ValueError(msg)
matrix = np.array(list)
matrix = matrix.reshape(3,3)
return {
'mean': calcMeans(matrix),
'variance': calcVariance(matrix),
'standard deviation': calcStd(matrix),
'max': calcMax(matrix),
'min': calcMin(matrix),
'sum': calcSum(matrix),
}
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.61 Safari/537.36
.
Challenge: Mean-Variance-Standard Deviation Calculator
Link to the challenge: