Mean-Variance Calculator: Test Error

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:

Welcome, trottz.

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 (’).


You are much more likely to get help, if you provide a link to your Repl.it (if you are doing your project there).

Thanks

1 Like