+ 1

Python. Can someone pls explain me this code.

Def func(*args) x = 0 for a in args: x+=a return x/len (args) print (func(3,4,5))

21st Sep 2018, 5:01 AM
AMAN TOMAR
AMAN TOMAR - avatar
3 Respostas
+ 3
indentation looks wrong, defines function named func. func takes an unlimited amount of argument which are stored in args denoted by the single *. adds 1 to x for each arg which is the same thing as length, returns this so should always return 1
21st Sep 2018, 5:07 AM
JME
+ 3
wait my bad x is the sum of arguments, then divided by the length, so it returns the average
21st Sep 2018, 5:09 AM
JME
0
thank you so much.
21st Sep 2018, 5:08 AM
AMAN TOMAR
AMAN TOMAR - avatar