Data Analysis with Python Mean-Variance-Standard Deviation Calculator

Tell us what’s happening:
Describe your issue in detail here.
I’m getting an error when submitting this code. The error states that ValueError is not raised by calculate. However, when ran on my own IDE, the ValueError is raised.

def calculate(a):
try:
arr = np.array(a)
arr = np.reshape(arr, (3, 3))

``````    mean_row = np.mean(arr, axis = 0).tolist()
mean_col = np.mean(arr, axis = 1).tolist()
mean_flat = np.mean(arr.flatten()).tolist()
mean_list = [mean_row, mean_col, mean_flat]

var_row = np.var(arr, axis = 0).tolist()
var_col = np.var(arr, axis = 1).tolist()
var_flat = np.var(arr.flatten()).tolist()
var_list = [var_row, var_col, var_flat]

std_row = np.std(arr, axis = 0).tolist()
std_col = np.std(arr, axis = 1).tolist()
std_flat = np.std(arr.flatten()).tolist()
std_list = [std_row, std_col, std_flat]

max_row = np.max(arr, axis = 0).tolist()
max_col = np.max(arr, axis = 1).tolist()
max_flat = np.max(arr.flatten()).tolist()
max_list = [max_row, max_col, max_flat]

min_row = np.min(arr, axis = 0).tolist()
min_col = np.min(arr, axis = 1).tolist()
min_flat = np.min(arr.flatten()).tolist()
min_list = [min_row, min_col, min_flat]

sum_row = np.sum(arr, axis = 0).tolist()
sum_col = np.sum(arr, axis = 1).tolist()
sum_flat = np.sum(arr.flatten()).tolist()
sum_list = [sum_row, sum_col, sum_flat]

keys = ['mean', 'variance', 'standard deviation', 'max', 'min', 'sum']
values = [mean_list, var_list, std_list, max_list, min_list, sum_list]

calculations = dict(zip(keys, values))

return calculations

except ValueError:
return "List must contain nine numbers."
``````

User Agent is: ` Chrome/90.0.4430.212 `

Challenge: Mean-Variance-Standard Deviation Calculator

The except ValueError should be a raise, like this:

``````raise ValueError("List must contain nine numbers.")
``````

If not, the UnitTest will not match your message with the expected message

Yes, this worked! Thank you so much.

1 Like

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