# Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator Problems

Hello,
I don’t know why the following code is not working with the test solutions. I think I’m having issues with the formatting they want, but I can’t figure out how to correct it.

``````def calculate(list):
if len(list) != 9:
raise ValueError("List must contain nine numbers")
list=np.asarray(list)
list=list.reshape(3,3)
meanaxis1 = np.mean(list, axis=0)
meanaxis2 = np.mean(list, axis=1)
meanflat = np.mean(list)
varaxis1 = np.var(list,axis=0)
varaxis2 = np.var(list,axis=1)
varflat = np.var(list)
stdaxis1 = np.std(list,axis=0)
stdaxis2 = np.std(list,axis=1)
stdflat = np.std(list)
maxaxis1 = np.max(list,axis=0)
maxaxis2 = np.max(list,axis=1)
maxflat = np.max(list)
minaxis1 = np.min(list,axis=0)
minaxis2 = np.min(list,axis=1)
minflat = np.min(list)
sumaxis1 = np.sum(list,axis=0)
sumaxis2 = np.sum(list,axis=1)
sumflat = np.sum(list)

calculations = {
'mean': [meanaxis1, meanaxis2, meanflat],
'variance': [varaxis1, varaxis2, varflat],
'standard deviation': [stdaxis1, stdaxis2, stdflat],
'max': [maxaxis1, maxaxis2, maxflat],
'min': [minaxis1, minaxis2, minflat],
'sum': [sumaxis1, sumaxis2, sumflat]}

return calculations
``````

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

Hi,
Did you checked the type of returned data?
`The values in the returned dictionary should be lists and not Numpy arrays`
As I see you return numpy arrays instead of python lists.
If you don’t know how to change the type, then use google search: `np array to list`

lendoo

1 Like