I can't write a python average function that will average 3 input integers from user. (average has to be in float) -


can't write functional python code asks users enter 3 integers, pass through function named (avg) , return average (float) value.

the formula average sum of arguments divided amount of arguments. add 3 arguments , divide 3 want!

   def average(a,b,c):         mean = (a + b + c)/3.0         return mean 

note: use 3.0 instead of 3 result float!

now on top of of this, might want function deal bunch of different inputs! *args way want can write function take arbitrary number of arguments average:

in [45]: def average(*args):    ....:     return sum(args)/float(len(args))    ....:   in [46]: average(1,10,4,5,8,9) out[46]: 6.166666666666667 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -