# 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

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)
``````

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

What error are you getting exactly?

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

You probably meant if and not while there… Typos happen

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

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