Tell us what’s happening:
hello , my code is working with any list of 9 numbers including those in the test modules but the 3rd test always give me an error(when I enter a list that is not 9 digits) so what’s wrong with my code?
Your code so far
import numpy as np
def calculate(lst):
dik = {}
lol = ['mean', 'variance', 'standard deviation', 'max', 'min', 'sum']
k = np.array(lst)
try:
a = k.reshape((3, 3))
except ValueError:
return 'List must contain nine numbers.'
b = np.array([a.mean(axis=0).tolist(), a.mean(
axis=1).tolist(), a.mean()]).tolist()
c = np.array([a.var(axis=0).tolist(), a.var(
axis=1).tolist(), a.var()]).tolist()
d = np.array([a.std(axis=0).tolist(), a.std(
axis=1).tolist(), a.std()]).tolist()
e = np.array([a.min(axis=0).tolist(), a.min(
axis=1).tolist(), a.min()]).tolist()
f = np.array([a.max(axis=0).tolist(), a.max(
axis=1).tolist(), a.max()]).tolist()
g = np.array([a.sum(axis=0).tolist(), a.sum(
axis=1).tolist(), a.sum()]).tolist()
bob = [b, c, d, f, e, g]
for (i, j) in zip(lol, bob):
dik[i] = j
return dik
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
Challenge: Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator
Link to the challenge:
this is the error i get