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

Tell us what’s happening:
Describe your issue in detail here.
I’m getting this error TypeError: unsupported operand type(s) for -: ‘type’ and ‘dict’

I have ran my code in my local IDE and it works fine and also throws ValueError if the given list contains less that 9 elements.

Your code so far
import numpy as np

def calculate(list):
if len(list)==9:
arr=np.array(list).reshape(3,3)
mean=[[arr[:,:1].mean(),arr[:,1:2].mean(),arr[:,2:].mean()],[arr[:1,:].mean(),arr[1:2,:].mean(),arr[2:,:].mean()],arr.mean()]
var=[[arr[:,:1].var(),arr[:,1:2].var(),arr[:,2:].var()],[arr[:1,:].var(),arr[1:2,:].var(),arr[2:,:].var()],arr.var()]
std=[[arr[:,:1].std(),arr[:,1:2].std(),arr[:,2:].std()],[arr[:1,:].std(),arr[1:2,:].std(),arr[2:,:].std()],arr.std()]
max=[[arr[:,:1].max(),arr[:,1:2].max(),arr[:,2:].max()],[arr[:1,:].max(),arr[1:2,:].max(),arr[2:,:].max()],arr.max()]
min=[[arr[:,:1].min(),arr[:,1:2].min(),arr[:,2:].min()],[arr[:1,:].min(),arr[1:2,:].min(),arr[2:,:].min()],arr.min()]
sum=[[arr[:,:1].sum(),arr[:,1:2].sum(),arr[:,2:].sum()],[arr[:1,:].sum(),arr[1:2,:].sum(),arr[2:,:].sum()],arr.sum()]

  Calculations=dict([('Mean',mean),('Variance',var),("Standard Deviation",std),('Max',max),('Min',min),('Sum',sum)])

  return type(sum)

else:
  raise ValueError('List must contain nine numbers.')

Your browser information:
Chrome Browser

Challenge: Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator

Link to the challenge:

That error might be a bit misleading, but in here it means that result returned by function is not the same as expected result.

The result coming from my code matches with the one one present in the test_conditions template.

You can try running the above code and check

From what I can see, the capitalization of dictionary keys are different in what function returns.

hey, I am about to start this course but I noticed that the notebooks.ai which is used in this course is shutted down 2 years ago and we should use google colab instead. so is this course still usefull as it say how to work with notebooks.ai?

notebooks.ai isn’t necessary for Jupyter notebooks, I believe it was just an option for storing and editing Jupyter Notebook files and the preferred one of the person who presents the lessons, but there are plenty of other options like just running Jupyter through the command prompt or using the Google Research collab option.

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