Tell us what’s happening:
I don’t know how to return ValueError to have not fails in the test that runs in the first project of the course “Data Analysis with Python” → “mean_var_std.py”
Can anyone help me? I’m sure it’s something really simple but I’ve tried to google it and found nothing.
Your code so far
def calculate(list):
try:
nplist = np.array(list).reshape(3,3)
mean =([nplist.mean(0).tolist(),nplist.mean(1).tolist(),float(nplist.mean())])
variance = ([nplist.var(0).tolist(),nplist.var(1).tolist(),float(nplist.var())])
std_deviation = ([nplist.std(0).tolist(),nplist.std(1).tolist(),float(nplist.std())])
max = ([nplist.max(0).tolist(),nplist.max(1).tolist(),float(nplist.max())])
min = ([nplist.min(0).tolist(),nplist.min(1).tolist(),float(nplist.min())])
sum = ([nplist.sum(0).tolist(),nplist.sum(1).tolist(),float(nplist.sum())])
calculations = {
"mean": mean,
"variance": variance,
"standard deviation": std_deviation,
"max": max,
"min": min,
"sum": sum
}
return calculations
except ValueError:
return "List must contain nine numbers."
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
Challenge: Mean-Variance-Standard Deviation Calculator
Link to the challenge: