I can't return ValueError in Data Analysis with Python first Proyect "mean_var_std.py"

Tell us what’s happening:
I don’t know how to return ValueError to have not fails in the test that runs in the first project of the course “Data Analysis with Python” → “mean_var_std.py”

Can anyone help me? I’m sure it’s something really simple but I’ve tried to google it and found nothing.

Your code so far

   def calculate(list):

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

      mean =([nplist.mean(0).tolist(),nplist.mean(1).tolist(),float(nplist.mean())])
      variance = ([nplist.var(0).tolist(),nplist.var(1).tolist(),float(nplist.var())])
      std_deviation = ([nplist.std(0).tolist(),nplist.std(1).tolist(),float(nplist.std())])
      max = ([nplist.max(0).tolist(),nplist.max(1).tolist(),float(nplist.max())])
      min = ([nplist.min(0).tolist(),nplist.min(1).tolist(),float(nplist.min())])
      sum = ([nplist.sum(0).tolist(),nplist.sum(1).tolist(),float(nplist.sum())])
      calculations = {
        "mean": mean,
        "variance": variance,
        "standard deviation": std_deviation,
        "max": max,
        "min": min,
        "sum": sum
      return calculations
    except ValueError:
      return "List must contain nine numbers."

Your browser information:

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

Challenge: Mean-Variance-Standard Deviation Calculator

Link to the challenge:

The task is to “raise” a ValueError. Which is literally done with the “raise ValueError()”: 8. Errors and Exceptions — Python 3.10.5 documentation

So yeah, it’s a simple thing - which might still be hard to google if you don’t know that this is a specific keyword :wink:

1 Like

Thank you very much! It´s still giving me error on the test (weird), but at least I know how to return an error properly :slight_smile: