Getting Value Error:Mean-Variance-Standard Deviation Calculator

Tell us what’s happening:
Describe your issue in detail here.
Showing Value error unable to understand , as i have raised Value error exception without try and except .Confused!! Need help

Your code so far
while len(list_1)!=9:
raise ValueError(“List must contain nine numbers”)
else:

    a=np.array(list_1)
    b=a.reshape(3,3)
#MEAN    
    c_mean=b.mean(axis=0).tolist()
    d_mean=b.mean(axis=1).tolist()
    e_mean=b.mean().tolist()
    f_mean=[c_mean,d_mean,e_mean]
#VAR    
    c_var=b.var(axis=0).tolist()
    d_var=b.var(axis=1).tolist()
    e_var=b.var().tolist()
    f_var=[c_var,d_var,e_var]
#STD
    c_std=b.std(axis=0).tolist()
    d_std=b.std(axis=1).tolist()
    e_std=b.std().tolist()
    f_std=[c_std,d_std,e_std]
#MAX    
    c_max=b.max(axis=0).tolist()
    d_max=b.max(axis=1).tolist()
    e_max=b.max().tolist()
    f_max=[c_max,d_max,e_max]
#MIN
    c_min=b.min(axis=0).tolist()
    d_min=b.min(axis=1).tolist()
    e_min=b.min().tolist()
    f_min=[c_min,d_min,e_min]
#SUM
    c_sum=b.sum(axis=0).tolist()
    d_sum=b.sum(axis=1).tolist()
    e_sum=b.sum().tolist()
    f_sum=[c_sum,d_sum,e_sum]

    calculations={  'mean': f_mean,'variance': f_var,'standard deviation': f_std,'max': f_max,'min': f_min,'sum': f_sum }        
    print(calculations)

Your browser information:

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

Challenge: Mean-Variance-Standard Deviation Calculator

Link to the challenge:

What error are you getting exactly?

Could you paste complete code of your function and/or link to your code at the replit?

Hi…

So ValueError is a type of exception you raise in cases where a certain value does not meet requirements - in this case when the list has less than 9 items.

It should stop the execution of the program with a traceback (unless raised inside a try-except structure - which this exercise does not want you to do)… So if the code ends up in traceback (if condition for Valueerror), then it’s working as it should :slight_smile:

You probably meant if and not while there… Typos happen :slight_smile:

Also, you’re not looking for lists of length != 9, rather, you are looking to filter out lists of length < 9… (10 item lists should run okay)

Haven’t read the rest of the code but I hope that covered the bit about ValueError…

Happy debugging :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.