New course! Every coder should learn Generative AI!
Try a free lesson- 1
Write a FUNCTION(def) average that accepts a variable number of integer positional arguments and computes the average.
Write a FUNCTION(def) average that accepts a variable number of integer positional arguments and computes the average. If no arguments are supplied, the function should return None.
2 Answers
+ 1
def average(*args):
if len(args) == 0:
return None
sum = 0
for arg in args:
sum += arg
return sum / len(args)
print(average(1,2,3,4,5,6,7,8,9))
0
Thank you so much. I wanted to ask what the * sign means before args?