-1

So I am trying to define function to calculate mean and st.dev (without packages) of a given series of numbers, also the function must be provided with a minimum of 2 numbers, where *arg means I can use any list of numbers>1

def avg(x,y,*arg): return (x+y)/2 if len(arg)<1 else (x+y+sum(arg))/(2+len(arg))

def stddev(x,y,*arg):
    
    mu = (x+y)/2 if len(arg)<1 else (x+y+sum(arg))/(2+len(arg))
    return ([x - mu] ** 2/len(arg))**0.5
Maria
  • 1
  • 2

1 Answers1

0

[x - mu] ** 2/len(arg) will throw an error since can't take power (using **) of a list only an int/float. Also optional arguments to a function should be listed as **args like this: def avg(x,y,**args):. x when passed into stddev() should be a float or if subtracting a scalar from a list use something like this: [ele - mu for ele in x]